@hamur/adapter-angular 0.0.1 → 0.0.3

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.
@@ -1,5 +1,6 @@
1
1
  import { type Type } from "@angular/core";
2
2
  import type { MarkdownDocument, MdNode } from "hamur/markdown";
3
+ import * as i0 from "@angular/core";
3
4
  export interface MarkdownRendererProps {
4
5
  /** A Markdown AST node, a list of nodes, or a document, which renders its `ast`. */
5
6
  value: MdNode | MdNode[] | MarkdownDocument;
@@ -18,9 +19,9 @@ type Components = Record<string, Type<unknown>>;
18
19
  * the host in hydration and the browser builds them again from the same AST.
19
20
  */
20
21
  export declare class MarkdownRenderer {
21
- readonly value: import("@angular/core/types/core.js").InputSignal<MdNode[] | MarkdownDocument | MdNode>;
22
- readonly components: import("@angular/core/types/core.js").InputSignal<Components | undefined>;
23
- readonly raw: import("@angular/core/types/core.js").InputSignal<((html: string) => string | {
22
+ readonly value: import("@angular/core").InputSignal<MdNode | MarkdownDocument | MdNode[]>;
23
+ readonly components: import("@angular/core").InputSignal<Components | undefined>;
24
+ readonly raw: import("@angular/core").InputSignal<((html: string) => string | {
24
25
  readonly __brand: "TrustedHTML";
25
26
  }) | undefined>;
26
27
  private readonly host;
@@ -33,5 +34,7 @@ export declare class MarkdownRenderer {
33
34
  constructor();
34
35
  private append;
35
36
  private appendComponent;
37
+ static ɵfac: i0.ɵɵFactoryDeclaration<MarkdownRenderer, never>;
38
+ static ɵcmp: i0.ɵɵComponentDeclaration<MarkdownRenderer, "hamur-markdown", never, { "value": { "alias": "value"; "required": true; "isSignal": true; }; "components": { "alias": "components"; "required": false; "isSignal": true; }; "raw": { "alias": "raw"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
36
39
  }
37
40
  export {};
@@ -1,14 +1,17 @@
1
1
  import { type OnInit } from "@angular/core";
2
+ import * as i0 from "@angular/core";
2
3
  /** Navigates to `to` once after mount; during SSR it throws the redirect `navigateTo` throws there. */
3
4
  export declare class Navigate<T extends string = string> implements OnInit {
4
- readonly to: import("@angular/core/types/core").InputSignal<T | ({
5
+ readonly to: import("@angular/core").InputSignal<({
5
6
  name: string;
6
7
  query?: Record<string, string | string[]>;
7
8
  hash?: string;
8
9
  } & {
9
10
  params?: Record<string, string | string[]> | undefined;
10
- })>;
11
- readonly replace: import("@angular/core/types/core").InputSignalWithTransform<boolean, unknown>;
11
+ }) | T>;
12
+ readonly replace: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
12
13
  constructor();
13
14
  ngOnInit(): void;
15
+ static ɵfac: i0.ɵɵFactoryDeclaration<Navigate<any>, never>;
16
+ static ɵcmp: i0.ɵɵComponentDeclaration<Navigate<any>, "hamur-navigate", never, { "to": { "alias": "to"; "required": true; "isSignal": true; }; "replace": { "alias": "replace"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
14
17
  }
@@ -1,12 +1,13 @@
1
1
  import { type OnInit, type Signal } from "@angular/core";
2
2
  import type { KeptUnit, RenderContext, RenderTree, RouteValue } from "hamur/adapter";
3
+ import * as i0 from "@angular/core";
3
4
  /**
4
5
  * Places the next level of the tree as its next sibling; the `hamur-outlet` element stays empty. With `name` it places
5
6
  * the chain of that slot of the entry it sits in; `context` reaches the entries below through `injectOutletContext()`.
6
7
  */
7
8
  export declare class Outlet implements OnInit {
8
- readonly name: import("@angular/core/types/core.js").InputSignal<string | undefined>;
9
- readonly context: import("@angular/core/types/core.js").InputSignal<unknown>;
9
+ readonly name: import("@angular/core").InputSignal<string | undefined>;
10
+ readonly context: import("@angular/core").InputSignal<unknown>;
10
11
  private readonly tree;
11
12
  private readonly fail;
12
13
  private readonly app;
@@ -52,15 +53,17 @@ export declare class Outlet implements OnInit {
52
53
  private answer;
53
54
  private clear;
54
55
  private setInputs;
56
+ static ɵfac: i0.ɵɵFactoryDeclaration<Outlet, never>;
57
+ static ɵcmp: i0.ɵɵComponentDeclaration<Outlet, "hamur-outlet", never, { "name": { "alias": "name"; "required": false; "isSignal": true; }; "context": { "alias": "context"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
55
58
  }
56
59
  /**
57
60
  * The `<div data-hamur-keepalive="<key>">` of a page whose route keeps its pages, `display:contents` while it is shown
58
61
  * and `hidden` while kept. A kept unit reads its own tree, route and payload; a shown one reads the page's, from its own level down.
59
62
  */
60
63
  export declare class KeptPage {
61
- readonly name: import("@angular/core/types/core.js").InputSignal<string>;
62
- readonly unit: import("@angular/core/types/core.js").InputSignal<KeptUnit | undefined>;
63
- readonly hidden: import("@angular/core/types/core.js").InputSignal<boolean>;
64
+ readonly name: import("@angular/core").InputSignal<string>;
65
+ readonly unit: import("@angular/core").InputSignal<KeptUnit | undefined>;
66
+ readonly hidden: import("@angular/core").InputSignal<boolean>;
64
67
  private readonly source;
65
68
  private readonly app;
66
69
  readonly activation: import("./activation.ts").Activation;
@@ -68,4 +71,6 @@ export declare class KeptPage {
68
71
  readonly route: Signal<RouteValue>;
69
72
  readonly payload: Signal<RenderContext["payload"]>;
70
73
  constructor();
74
+ static ɵfac: i0.ɵɵFactoryDeclaration<KeptPage, never>;
75
+ static ɵcmp: i0.ɵɵComponentDeclaration<KeptPage, "div[data-hamur-keepalive]", never, { "name": { "alias": "name"; "required": true; "isSignal": true; }; "unit": { "alias": "unit"; "required": false; "isSignal": true; }; "hidden": { "alias": "hidden"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
71
76
  }
@@ -1,15 +1,16 @@
1
1
  import { type OnInit, type TemplateRef } from "@angular/core";
2
2
  import { HostWriter } from "./island.ts";
3
+ import * as i0 from "@angular/core";
3
4
  /**
4
5
  * A component rendered on the server in its own request; the page holds `fallback`, the core swaps the answer in, and Angular
5
6
  * never renders or hydrates it. While hydrating, the server's element keeps its attributes and nodes.
6
7
  */
7
8
  export declare class ServerIsland extends HostWriter implements OnInit {
8
9
  /** The name of a component under `app/server-islands/`. */
9
- readonly name: import("@angular/core/types/core.js").InputSignal<string>;
10
- readonly props: import("@angular/core/types/core.js").InputSignal<Record<string, unknown> | undefined>;
10
+ readonly name: import("@angular/core").InputSignal<string>;
11
+ readonly props: import("@angular/core").InputSignal<Record<string, unknown> | undefined>;
11
12
  /** Rendered with the page; replaced by the island's HTML once the browser has it. */
12
- readonly fallback: import("@angular/core/types/core.js").InputSignal<TemplateRef<unknown> | undefined>;
13
+ readonly fallback: import("@angular/core").InputSignal<TemplateRef<unknown> | undefined>;
13
14
  private readonly app;
14
15
  private readonly id;
15
16
  private readonly tasks;
@@ -18,4 +19,6 @@ export declare class ServerIsland extends HostWriter implements OnInit {
18
19
  private readonly kept;
19
20
  constructor();
20
21
  ngOnInit(): void;
22
+ static ɵfac: i0.ɵɵFactoryDeclaration<ServerIsland, never>;
23
+ static ɵcmp: i0.ɵɵComponentDeclaration<ServerIsland, "hamur-server-island", never, { "name": { "alias": "name"; "required": true; "isSignal": true; }; "props": { "alias": "props"; "required": false; "isSignal": true; }; "fallback": { "alias": "fallback"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
21
24
  }
@@ -1,37 +1,40 @@
1
+ import * as i0 from "@angular/core";
1
2
  /**
2
3
  * `<time [hamurTime]="date">` writes the `datetime`, `data-locale` and `data-time-zone` attributes and the formatted text;
3
4
  * `relative` refreshes the text every `relativeInterval` ms in the browser. The other inputs are the `Intl.DateTimeFormat` options.
4
5
  */
5
6
  export declare class Time {
6
- readonly datetime: import("@angular/core/types/core.js").InputSignal<string | number | Date>;
7
- readonly locale: import("@angular/core/types/core.js").InputSignal<string | undefined>;
8
- readonly timeZone: import("@angular/core/types/core.js").InputSignal<string | undefined>;
9
- readonly relative: import("@angular/core/types/core.js").InputSignalWithTransform<boolean, unknown>;
10
- readonly relativeInterval: import("@angular/core/types/core.js").InputSignalWithTransform<number | undefined, unknown>;
11
- readonly calendar: import("@angular/core/types/core.js").InputSignal<string | undefined>;
12
- readonly dayPeriod: import("@angular/core/types/core.js").InputSignal<"long" | "narrow" | "short" | undefined>;
13
- readonly numberingSystem: import("@angular/core/types/core.js").InputSignal<string | undefined>;
14
- readonly dateStyle: import("@angular/core/types/core.js").InputSignal<"full" | "long" | "medium" | "short" | undefined>;
15
- readonly timeStyle: import("@angular/core/types/core.js").InputSignal<"full" | "long" | "medium" | "short" | undefined>;
16
- readonly hourCycle: import("@angular/core/types/core.js").InputSignal<"h11" | "h12" | "h23" | "h24" | undefined>;
17
- readonly hour12: import("@angular/core/types/core.js").InputSignalWithTransform<boolean | undefined, unknown>;
18
- readonly localeMatcher: import("@angular/core/types/core.js").InputSignal<"best fit" | "lookup" | undefined>;
19
- readonly formatMatcher: import("@angular/core/types/core.js").InputSignal<"basic" | "best fit" | undefined>;
20
- readonly weekday: import("@angular/core/types/core.js").InputSignal<"long" | "narrow" | "short" | undefined>;
21
- readonly era: import("@angular/core/types/core.js").InputSignal<"long" | "narrow" | "short" | undefined>;
22
- readonly year: import("@angular/core/types/core.js").InputSignal<"2-digit" | "numeric" | undefined>;
23
- readonly month: import("@angular/core/types/core.js").InputSignal<"2-digit" | "long" | "narrow" | "numeric" | "short" | undefined>;
24
- readonly day: import("@angular/core/types/core.js").InputSignal<"2-digit" | "numeric" | undefined>;
25
- readonly hour: import("@angular/core/types/core.js").InputSignal<"2-digit" | "numeric" | undefined>;
26
- readonly minute: import("@angular/core/types/core.js").InputSignal<"2-digit" | "numeric" | undefined>;
27
- readonly second: import("@angular/core/types/core.js").InputSignal<"2-digit" | "numeric" | undefined>;
28
- readonly fractionalSecondDigits: import("@angular/core/types/core.js").InputSignalWithTransform<1 | 2 | 3 | undefined, unknown>;
29
- readonly timeZoneName: import("@angular/core/types/core.js").InputSignal<"long" | "longGeneric" | "longOffset" | "short" | "shortGeneric" | "shortOffset" | undefined>;
7
+ readonly datetime: import("@angular/core").InputSignal<string | number | Date>;
8
+ readonly locale: import("@angular/core").InputSignal<string | undefined>;
9
+ readonly timeZone: import("@angular/core").InputSignal<string | undefined>;
10
+ readonly relative: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
11
+ readonly relativeInterval: import("@angular/core").InputSignalWithTransform<number | undefined, unknown>;
12
+ readonly calendar: import("@angular/core").InputSignal<string | undefined>;
13
+ readonly dayPeriod: import("@angular/core").InputSignal<"narrow" | "short" | "long" | undefined>;
14
+ readonly numberingSystem: import("@angular/core").InputSignal<string | undefined>;
15
+ readonly dateStyle: import("@angular/core").InputSignal<"short" | "long" | "full" | "medium" | undefined>;
16
+ readonly timeStyle: import("@angular/core").InputSignal<"short" | "long" | "full" | "medium" | undefined>;
17
+ readonly hourCycle: import("@angular/core").InputSignal<"h11" | "h12" | "h23" | "h24" | undefined>;
18
+ readonly hour12: import("@angular/core").InputSignalWithTransform<boolean | undefined, unknown>;
19
+ readonly localeMatcher: import("@angular/core").InputSignal<"best fit" | "lookup" | undefined>;
20
+ readonly formatMatcher: import("@angular/core").InputSignal<"best fit" | "basic" | undefined>;
21
+ readonly weekday: import("@angular/core").InputSignal<"narrow" | "short" | "long" | undefined>;
22
+ readonly era: import("@angular/core").InputSignal<"narrow" | "short" | "long" | undefined>;
23
+ readonly year: import("@angular/core").InputSignal<"numeric" | "2-digit" | undefined>;
24
+ readonly month: import("@angular/core").InputSignal<"narrow" | "short" | "long" | "numeric" | "2-digit" | undefined>;
25
+ readonly day: import("@angular/core").InputSignal<"numeric" | "2-digit" | undefined>;
26
+ readonly hour: import("@angular/core").InputSignal<"numeric" | "2-digit" | undefined>;
27
+ readonly minute: import("@angular/core").InputSignal<"numeric" | "2-digit" | undefined>;
28
+ readonly second: import("@angular/core").InputSignal<"numeric" | "2-digit" | undefined>;
29
+ readonly fractionalSecondDigits: import("@angular/core").InputSignalWithTransform<1 | 2 | 3 | undefined, unknown>;
30
+ readonly timeZoneName: import("@angular/core").InputSignal<"short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric" | undefined>;
30
31
  private readonly app;
31
32
  private readonly route;
32
33
  private readonly now;
33
34
  private readonly props;
34
- protected readonly view: import("@angular/core/types/_chrome_dev_tools_performance-chunk.js").Signal<import("hamur/adapter").TimeView>;
35
+ protected readonly view: import("@angular/core").Signal<import("hamur/adapter").TimeView>;
35
36
  private readonly interval;
36
37
  constructor();
38
+ static ɵfac: i0.ɵɵFactoryDeclaration<Time, never>;
39
+ static ɵdir: i0.ɵɵDirectiveDeclaration<Time, "time[hamurTime]", never, { "datetime": { "alias": "hamurTime"; "required": true; "isSignal": true; }; "locale": { "alias": "locale"; "required": false; "isSignal": true; }; "timeZone": { "alias": "timeZone"; "required": false; "isSignal": true; }; "relative": { "alias": "relative"; "required": false; "isSignal": true; }; "relativeInterval": { "alias": "relativeInterval"; "required": false; "isSignal": true; }; "calendar": { "alias": "calendar"; "required": false; "isSignal": true; }; "dayPeriod": { "alias": "dayPeriod"; "required": false; "isSignal": true; }; "numberingSystem": { "alias": "numberingSystem"; "required": false; "isSignal": true; }; "dateStyle": { "alias": "dateStyle"; "required": false; "isSignal": true; }; "timeStyle": { "alias": "timeStyle"; "required": false; "isSignal": true; }; "hourCycle": { "alias": "hourCycle"; "required": false; "isSignal": true; }; "hour12": { "alias": "hour12"; "required": false; "isSignal": true; }; "localeMatcher": { "alias": "localeMatcher"; "required": false; "isSignal": true; }; "formatMatcher": { "alias": "formatMatcher"; "required": false; "isSignal": true; }; "weekday": { "alias": "weekday"; "required": false; "isSignal": true; }; "era": { "alias": "era"; "required": false; "isSignal": true; }; "year": { "alias": "year"; "required": false; "isSignal": true; }; "month": { "alias": "month"; "required": false; "isSignal": true; }; "day": { "alias": "day"; "required": false; "isSignal": true; }; "hour": { "alias": "hour"; "required": false; "isSignal": true; }; "minute": { "alias": "minute"; "required": false; "isSignal": true; }; "second": { "alias": "second"; "required": false; "isSignal": true; }; "fractionalSecondDigits": { "alias": "fractionalSecondDigits"; "required": false; "isSignal": true; }; "timeZoneName": { "alias": "timeZoneName"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
37
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamur/adapter-angular",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,31 +11,52 @@
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./dist/types/src/index.d.ts",
14
- "default": "./dist/src/index.js"
14
+ "bun": "./src/index.ts",
15
+ "hamur-source": "./src/index.ts",
16
+ "node": "./dist/src/index.js",
17
+ "default": "./src/index.ts"
15
18
  },
16
19
  "./adapter": {
17
20
  "types": "./dist/types/src/adapter.d.ts",
18
- "default": "./dist/src/adapter.js"
21
+ "bun": "./src/adapter.ts",
22
+ "hamur-source": "./src/adapter.ts",
23
+ "node": "./dist/src/adapter.js",
24
+ "default": "./src/adapter.ts"
19
25
  },
20
26
  "./error-page": {
21
27
  "types": "./dist/types/src/error-page.d.ts",
22
- "default": "./dist/src/error-page.js"
28
+ "bun": "./src/error-page.ts",
29
+ "hamur-source": "./src/error-page.ts",
30
+ "node": "./dist/src/error-page.js",
31
+ "default": "./src/error-page.ts"
23
32
  },
24
33
  "./runtime/server": {
25
34
  "types": "./dist/types/src/runtime/server.d.ts",
26
- "default": "./dist/src/runtime/server.js"
35
+ "bun": "./src/runtime/server.ts",
36
+ "hamur-source": "./src/runtime/server.ts",
37
+ "node": "./dist/src/runtime/server.js",
38
+ "default": "./src/runtime/server.ts"
27
39
  },
28
40
  "./runtime/client": {
29
41
  "types": "./dist/types/src/runtime/client.d.ts",
30
- "default": "./dist/src/runtime/client.js"
42
+ "bun": "./src/runtime/client.ts",
43
+ "hamur-source": "./src/runtime/client.ts",
44
+ "node": "./dist/src/runtime/client.js",
45
+ "default": "./src/runtime/client.ts"
31
46
  },
32
47
  "./runtime/island": {
33
48
  "types": "./dist/types/src/runtime/island.d.ts",
34
- "default": "./dist/src/runtime/island.js"
49
+ "bun": "./src/runtime/island.ts",
50
+ "hamur-source": "./src/runtime/island.ts",
51
+ "node": "./dist/src/runtime/island.js",
52
+ "default": "./src/runtime/island.ts"
35
53
  },
36
54
  "./runtime/keepalive": {
37
55
  "types": "./dist/types/src/keepalive.d.ts",
38
- "default": "./dist/src/keepalive.js"
56
+ "bun": "./src/keepalive.ts",
57
+ "hamur-source": "./src/keepalive.ts",
58
+ "node": "./dist/src/keepalive.js",
59
+ "default": "./src/keepalive.ts"
39
60
  },
40
61
  "./package.json": "./package.json"
41
62
  },
@@ -53,6 +74,6 @@
53
74
  "@angular/compiler-cli": "^22.3.0",
54
75
  "rxjs": "^7.8.2",
55
76
  "typescript": "~6.0.3",
56
- "hamur": "^0.0.1"
77
+ "hamur": "^0.0.3"
57
78
  }
58
79
  }
package/src/app.ts CHANGED
@@ -1,6 +1,12 @@
1
- import { Component } from "@angular/core"
2
- import { Outlet } from "./outlet.ts"
3
-
1
+ import { Component } from "@angular/core";
2
+ import { Outlet } from "./outlet.ts";
3
+ import * as i0 from "@angular/core";
4
4
  /** The one Angular root, inside the core's root element; it renders the tree's first entry. */
5
- @Component({ selector: "hamur-app", imports: [Outlet], template: "<hamur-outlet />" })
6
- export class HamurApp {}
5
+ export class HamurApp {
6
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: HamurApp, deps: [], target: i0.ɵɵFactoryTarget.Component });
7
+ 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: Outlet, selector: "hamur-outlet", inputs: ["name", "context"] }] });
8
+ }
9
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: HamurApp, decorators: [{
10
+ type: Component,
11
+ args: [{ selector: "hamur-app", imports: [Outlet], template: "<hamur-outlet />" }]
12
+ }] });
@@ -1,127 +1,107 @@
1
- import {
2
- APP_ID,
3
- DestroyRef,
4
- Directive,
5
- InjectionToken,
6
- PendingTasks,
7
- TemplateRef,
8
- ViewContainerRef,
9
- afterNextRender,
10
- assertInInjectionContext,
11
- computed,
12
- inject,
13
- signal,
14
- type Resource,
15
- type ResourceSnapshot,
16
- type Signal,
17
- } from "@angular/core"
18
- import { checkTransitionName, prehydrate, settledOf } from "hamur/adapter"
19
- import { HAMUR_APP, mode, onServer, required } from "./context.ts"
20
-
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";
21
5
  /**
22
6
  * `<div *hamurDevOnly>…</div>` renders its template only in a dev build. A production client keeps the template's code:
23
7
  * a component named in it is a static import of the compiled one.
24
8
  */
25
- @Directive({ selector: "[hamurDevOnly]" })
26
9
  export class DevOnly {
27
- constructor() {
28
- if (mode.dev) inject(ViewContainerRef).createEmbeddedView(inject(TemplateRef))
29
- }
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 });
30
16
  }
31
-
32
- const isThenable = (value: unknown): value is PromiseLike<unknown> =>
33
- typeof (value as { then?: unknown } | null)?.then === "function"
34
-
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";
35
22
  /**
36
23
  * The value of a promise a loader returned, as Angular's `Resource<T>`: read with `@if (value.hasValue()) … @else if
37
24
  * (value.error()) … @else …`. On the server the render waits for it; `value()` throws the error of a rejected promise,
38
25
  * as Angular's own resources do.
39
26
  */
40
- export function injectDeferred<T>(promise: PromiseLike<T> | T): Resource<Awaited<T>> {
41
- assertInInjectionContext(injectDeferred)
42
- type V = Awaited<T>
43
- const snapshot = signal<ResourceSnapshot<V | undefined>>({ status: "loading", value: undefined })
44
- const known = isThenable(promise) ? settledOf(promise) : ({ status: "fulfilled", value: promise } as const)
45
- if (known)
46
- snapshot.set(
47
- known.status === "fulfilled"
48
- ? { status: "resolved", value: known.value as V }
49
- : { status: "error", error: errorOf(known.reason) },
50
- )
51
- else {
52
- const done = onServer() ? inject(PendingTasks).add() : undefined
53
- const destroyed = { value: false }
54
- inject(DestroyRef).onDestroy(() => (destroyed.value = true))
55
- Promise.resolve(promise as PromiseLike<V>).then(
56
- (value) => {
57
- if (!destroyed.value) snapshot.set({ status: "resolved", value })
58
- done?.()
59
- },
60
- (reason: unknown) => {
61
- if (!destroyed.value) snapshot.set({ status: "error", error: errorOf(reason) })
62
- done?.()
63
- },
64
- )
65
- }
66
- const read = snapshot.asReadonly()
67
- return {
68
- value: computed(() => {
69
- const current = read()
70
- if (current.status === "error") throw current.error
71
- return current.value
72
- }),
73
- status: computed(() => read().status),
74
- error: computed(() => {
75
- const current = read()
76
- return current.status === "error" ? current.error : undefined
77
- }),
78
- isLoading: computed(() => read().status === "loading"),
79
- snapshot: read,
80
- hasValue: () => {
81
- const current = read()
82
- return current.status === "resolved"
83
- },
84
- } as unknown as Resource<V>
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
+ };
85
70
  }
86
-
87
- const errorOf = (reason: unknown): Error => (reason instanceof Error ? reason : new Error(String(reason)))
88
-
71
+ const errorOf = (reason) => (reason instanceof Error ? reason : new Error(String(reason)));
89
72
  /** `false` on the server and until the first render of a hydrated page is done; `true` at once after a client navigation. */
90
- export function injectHydrated(): Signal<boolean> {
91
- assertInInjectionContext(injectHydrated)
92
- const app = required(HAMUR_APP, "injectHydrated")
93
- const hydrated = signal(typeof document !== "undefined" && !onServer() && !app.asyncData.hydrating)
94
- const destroy = inject(DestroyRef)
95
- afterNextRender(() => {
96
- hydrated.set(!app.asyncData.hydrating)
97
- destroy.onDestroy(app.hooks.hook("app:mounted", () => hydrated.set(true)))
98
- })
99
- return hydrated.asReadonly()
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();
100
84
  }
101
-
102
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. */
103
- export const HAMUR_IDS = new InjectionToken<{ next: number; prefix: string }>("hamur ids", {
104
- providedIn: "root",
105
- factory: () => ({ next: 0, prefix: "" }),
106
- })
107
-
86
+ export const HAMUR_IDS = new InjectionToken("hamur ids", {
87
+ providedIn: "root",
88
+ factory: () => ({ next: 0, prefix: "" }),
89
+ });
108
90
  /**
109
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
110
92
  * its own, and the components of both renders are created in the same order.
111
93
  */
112
- export function injectId(): string {
113
- assertInInjectionContext(injectId)
114
- const counter = inject(HAMUR_IDS)
115
- return `${counter.prefix}${inject(APP_ID)}-${counter.next++}`
94
+ export function injectId() {
95
+ assertInInjectionContext(injectId);
96
+ const counter = inject(HAMUR_IDS);
97
+ return `${counter.prefix}${inject(APP_ID)}-${counter.next++}`;
116
98
  }
117
-
118
99
  /** The id for `data-hamur-p` on the element `fn` is called with, as an inline script before hydration; `undefined` in the browser. */
119
- export function onPrehydrate(fn: (el: Element) => void): string | undefined {
120
- assertInInjectionContext(onPrehydrate)
121
- return prehydrate(required(HAMUR_APP, "onPrehydrate"), fn)
100
+ export function onPrehydrate(fn) {
101
+ assertInInjectionContext(onPrehydrate);
102
+ return prehydrate(required(HAMUR_APP, "onPrehydrate"), fn);
122
103
  }
123
-
124
104
  /** The `[style]` that names an element for a view transition. */
125
- export function transitionName(name: string): { "view-transition-name": string } {
126
- return { "view-transition-name": checkTransitionName(name) }
105
+ export function transitionName(name) {
106
+ return { "view-transition-name": checkTransitionName(name) };
127
107
  }