@hamur/image 0.0.1 → 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.
@@ -1,6 +1,7 @@
1
1
  import { type OnInit } from "@angular/core";
2
2
  import type { ImageMeta } from "hamur";
3
3
  import type { ImageFit, ImageFormat, ImageModifiers } from "../types.ts";
4
+ import * as i0 from "@angular/core";
4
5
  /** An attribute binding takes a string, and `null` removes the attribute. */
5
6
  export declare const strings: (attributes: Record<string, unknown>) => Record<string, string | null>;
6
7
  /**
@@ -10,31 +11,33 @@ export declare const strings: (attributes: Record<string, unknown>) => Record<st
10
11
  * every write, so a binding that rewrites the server's equal value during hydration fires `load` again.
11
12
  */
12
13
  export declare class Img implements OnInit {
13
- readonly src: import("@angular/core/types/core.js").InputSignal<string | ImageMeta>;
14
- readonly alt: import("@angular/core/types/core.js").InputSignal<string | undefined>;
15
- readonly width: import("@angular/core/types/core.js").InputSignal<string | number | undefined>;
16
- readonly height: import("@angular/core/types/core.js").InputSignal<string | number | undefined>;
17
- readonly sizes: import("@angular/core/types/core.js").InputSignal<string | undefined>;
18
- readonly densities: import("@angular/core/types/core.js").InputSignal<number[] | undefined>;
19
- readonly format: import("@angular/core/types/core.js").InputSignal<ImageFormat | undefined>;
20
- readonly quality: import("@angular/core/types/core.js").InputSignalWithTransform<number | undefined, unknown>;
21
- readonly fit: import("@angular/core/types/core.js").InputSignal<ImageFit | undefined>;
22
- readonly modifiers: import("@angular/core/types/core.js").InputSignal<ImageModifiers | undefined>;
23
- readonly provider: import("@angular/core/types/core.js").InputSignal<string | undefined>;
24
- readonly preset: import("@angular/core/types/core.js").InputSignal<string | undefined>;
25
- readonly loading: import("@angular/core/types/core.js").InputSignal<"eager" | "lazy" | undefined>;
26
- readonly decoding: import("@angular/core/types/core.js").InputSignal<string | undefined>;
27
- readonly fetchpriority: import("@angular/core/types/core.js").InputSignal<"auto" | "high" | "low" | undefined>;
28
- readonly preload: import("@angular/core/types/core.js").InputSignalWithTransform<boolean, unknown>;
29
- readonly placeholder: import("@angular/core/types/core.js").InputSignal<string | undefined>;
30
- readonly placeholderClass: import("@angular/core/types/core.js").InputSignal<string | undefined>;
14
+ readonly src: import("@angular/core").InputSignal<string | ImageMeta>;
15
+ readonly alt: import("@angular/core").InputSignal<string | undefined>;
16
+ readonly width: import("@angular/core").InputSignal<string | number | undefined>;
17
+ readonly height: import("@angular/core").InputSignal<string | number | undefined>;
18
+ readonly sizes: import("@angular/core").InputSignal<string | undefined>;
19
+ readonly densities: import("@angular/core").InputSignal<number[] | undefined>;
20
+ readonly format: import("@angular/core").InputSignal<ImageFormat | undefined>;
21
+ readonly quality: import("@angular/core").InputSignalWithTransform<number | undefined, unknown>;
22
+ readonly fit: import("@angular/core").InputSignal<ImageFit | undefined>;
23
+ readonly modifiers: import("@angular/core").InputSignal<ImageModifiers | undefined>;
24
+ readonly provider: import("@angular/core").InputSignal<string | undefined>;
25
+ readonly preset: import("@angular/core").InputSignal<string | undefined>;
26
+ readonly loading: import("@angular/core").InputSignal<"lazy" | "eager" | undefined>;
27
+ readonly decoding: import("@angular/core").InputSignal<string | undefined>;
28
+ readonly fetchpriority: import("@angular/core").InputSignal<"high" | "low" | "auto" | undefined>;
29
+ readonly preload: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
30
+ readonly placeholder: import("@angular/core").InputSignal<string | undefined>;
31
+ readonly placeholderClass: import("@angular/core").InputSignal<string | undefined>;
31
32
  private readonly injector;
32
33
  private readonly loaded;
33
34
  private readonly events;
34
35
  private readonly resolved;
35
- protected readonly attrs: import("@angular/core/types/_chrome_dev_tools_performance-chunk.js").Signal<Record<string, string | null>>;
36
- protected readonly painted: import("@angular/core/types/_chrome_dev_tools_performance-chunk.js").Signal<Record<string, string>>;
37
- protected readonly paintedClass: import("@angular/core/types/_chrome_dev_tools_performance-chunk.js").Signal<string>;
36
+ protected readonly attrs: import("@angular/core").Signal<Record<string, string | null>>;
37
+ protected readonly painted: import("@angular/core").Signal<Record<string, string>>;
38
+ protected readonly paintedClass: import("@angular/core").Signal<string>;
38
39
  constructor();
39
40
  ngOnInit(): void;
41
+ static ɵfac: i0.ɵɵFactoryDeclaration<Img, never>;
42
+ static ɵdir: i0.ɵɵDirectiveDeclaration<Img, "img[hamurImg]", never, { "src": { "alias": "src"; "required": true; "isSignal": true; }; "alt": { "alias": "alt"; "required": false; "isSignal": true; }; "width": { "alias": "width"; "required": false; "isSignal": true; }; "height": { "alias": "height"; "required": false; "isSignal": true; }; "sizes": { "alias": "sizes"; "required": false; "isSignal": true; }; "densities": { "alias": "densities"; "required": false; "isSignal": true; }; "format": { "alias": "format"; "required": false; "isSignal": true; }; "quality": { "alias": "quality"; "required": false; "isSignal": true; }; "fit": { "alias": "fit"; "required": false; "isSignal": true; }; "modifiers": { "alias": "modifiers"; "required": false; "isSignal": true; }; "provider": { "alias": "provider"; "required": false; "isSignal": true; }; "preset": { "alias": "preset"; "required": false; "isSignal": true; }; "loading": { "alias": "loading"; "required": false; "isSignal": true; }; "decoding": { "alias": "decoding"; "required": false; "isSignal": true; }; "fetchpriority": { "alias": "fetchpriority"; "required": false; "isSignal": true; }; "preload": { "alias": "preload"; "required": false; "isSignal": true; }; "placeholder": { "alias": "placeholder"; "required": false; "isSignal": true; }; "placeholderClass": { "alias": "placeholderClass"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
40
43
  }
@@ -1,36 +1,39 @@
1
1
  import { type OnInit } from "@angular/core";
2
2
  import type { ImageMeta } from "hamur";
3
3
  import type { ImageFit, ImageFormat, ImageModifiers } from "../types.ts";
4
+ import * as i0 from "@angular/core";
4
5
  /**
5
6
  * `<hamur-picture src="/hero.jpg" format="webp" width="1200" alt="" />`, one `<source>` per format and the
6
7
  * `<img>` in the source's own format, or the `<img>` alone when the provider makes no other format.
7
8
  */
8
9
  export declare class Picture implements OnInit {
9
- readonly src: import("@angular/core/types/core.js").InputSignal<string | ImageMeta>;
10
- readonly alt: import("@angular/core/types/core.js").InputSignal<string | undefined>;
11
- readonly width: import("@angular/core/types/core.js").InputSignal<string | number | undefined>;
12
- readonly height: import("@angular/core/types/core.js").InputSignal<string | number | undefined>;
13
- readonly sizes: import("@angular/core/types/core.js").InputSignal<string | undefined>;
14
- readonly densities: import("@angular/core/types/core.js").InputSignal<number[] | undefined>;
15
- readonly format: import("@angular/core/types/core.js").InputSignal<ImageFormat[] | ImageFormat | undefined>;
16
- readonly legacyFormat: import("@angular/core/types/core.js").InputSignal<ImageFormat | undefined>;
17
- readonly quality: import("@angular/core/types/core.js").InputSignalWithTransform<number | undefined, unknown>;
18
- readonly fit: import("@angular/core/types/core.js").InputSignal<ImageFit | undefined>;
19
- readonly modifiers: import("@angular/core/types/core.js").InputSignal<ImageModifiers | undefined>;
20
- readonly provider: import("@angular/core/types/core.js").InputSignal<string | undefined>;
21
- readonly preset: import("@angular/core/types/core.js").InputSignal<string | undefined>;
22
- readonly loading: import("@angular/core/types/core.js").InputSignal<"eager" | "lazy" | undefined>;
23
- readonly decoding: import("@angular/core/types/core.js").InputSignal<string | undefined>;
24
- readonly fetchpriority: import("@angular/core/types/core.js").InputSignal<"auto" | "high" | "low" | undefined>;
25
- readonly preload: import("@angular/core/types/core.js").InputSignalWithTransform<boolean, unknown>;
26
- readonly placeholder: import("@angular/core/types/core.js").InputSignal<string | undefined>;
27
- readonly placeholderClass: import("@angular/core/types/core.js").InputSignal<string | undefined>;
10
+ readonly src: import("@angular/core").InputSignal<string | ImageMeta>;
11
+ readonly alt: import("@angular/core").InputSignal<string | undefined>;
12
+ readonly width: import("@angular/core").InputSignal<string | number | undefined>;
13
+ readonly height: import("@angular/core").InputSignal<string | number | undefined>;
14
+ readonly sizes: import("@angular/core").InputSignal<string | undefined>;
15
+ readonly densities: import("@angular/core").InputSignal<number[] | undefined>;
16
+ readonly format: import("@angular/core").InputSignal<ImageFormat | ImageFormat[] | undefined>;
17
+ readonly legacyFormat: import("@angular/core").InputSignal<ImageFormat | undefined>;
18
+ readonly quality: import("@angular/core").InputSignalWithTransform<number | undefined, unknown>;
19
+ readonly fit: import("@angular/core").InputSignal<ImageFit | undefined>;
20
+ readonly modifiers: import("@angular/core").InputSignal<ImageModifiers | undefined>;
21
+ readonly provider: import("@angular/core").InputSignal<string | undefined>;
22
+ readonly preset: import("@angular/core").InputSignal<string | undefined>;
23
+ readonly loading: import("@angular/core").InputSignal<"lazy" | "eager" | undefined>;
24
+ readonly decoding: import("@angular/core").InputSignal<string | undefined>;
25
+ readonly fetchpriority: import("@angular/core").InputSignal<"high" | "low" | "auto" | undefined>;
26
+ readonly preload: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
27
+ readonly placeholder: import("@angular/core").InputSignal<string | undefined>;
28
+ readonly placeholderClass: import("@angular/core").InputSignal<string | undefined>;
28
29
  private readonly injector;
29
30
  private readonly loaded;
30
31
  private readonly element;
31
32
  private readonly events;
32
- protected readonly parts: import("@angular/core/types/_chrome_dev_tools_performance-chunk.js").Signal<import("../runtime/picture.ts").PictureParts>;
33
- protected readonly shown: import("@angular/core/types/_chrome_dev_tools_performance-chunk.js").Signal<Record<string, string | null>>;
33
+ protected readonly parts: import("@angular/core").Signal<import("../runtime/picture.ts").PictureParts>;
34
+ protected readonly shown: import("@angular/core").Signal<Record<string, string | null>>;
34
35
  constructor();
35
36
  ngOnInit(): void;
37
+ static ɵfac: i0.ɵɵFactoryDeclaration<Picture, never>;
38
+ static ɵcmp: i0.ɵɵComponentDeclaration<Picture, "hamur-picture", never, { "src": { "alias": "src"; "required": true; "isSignal": true; }; "alt": { "alias": "alt"; "required": false; "isSignal": true; }; "width": { "alias": "width"; "required": false; "isSignal": true; }; "height": { "alias": "height"; "required": false; "isSignal": true; }; "sizes": { "alias": "sizes"; "required": false; "isSignal": true; }; "densities": { "alias": "densities"; "required": false; "isSignal": true; }; "format": { "alias": "format"; "required": false; "isSignal": true; }; "legacyFormat": { "alias": "legacyFormat"; "required": false; "isSignal": true; }; "quality": { "alias": "quality"; "required": false; "isSignal": true; }; "fit": { "alias": "fit"; "required": false; "isSignal": true; }; "modifiers": { "alias": "modifiers"; "required": false; "isSignal": true; }; "provider": { "alias": "provider"; "required": false; "isSignal": true; }; "preset": { "alias": "preset"; "required": false; "isSignal": true; }; "loading": { "alias": "loading"; "required": false; "isSignal": true; }; "decoding": { "alias": "decoding"; "required": false; "isSignal": true; }; "fetchpriority": { "alias": "fetchpriority"; "required": false; "isSignal": true; }; "preload": { "alias": "preload"; "required": false; "isSignal": true; }; "placeholder": { "alias": "placeholder"; "required": false; "isSignal": true; }; "placeholderClass": { "alias": "placeholderClass"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
36
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamur/image",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,39 +11,66 @@
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
  "./server": {
17
20
  "types": "./dist/types/src/server/index.d.ts",
18
- "default": "./dist/src/server/index.js"
21
+ "bun": "./src/server/index.ts",
22
+ "hamur-source": "./src/server/index.ts",
23
+ "node": "./dist/src/server/index.js",
24
+ "default": "./src/server/index.ts"
19
25
  },
20
26
  "./react": {
21
27
  "types": "./dist/types/src/adapters/react.d.ts",
22
- "default": "./dist/src/adapters/react.js"
28
+ "bun": "./src/adapters/react.ts",
29
+ "hamur-source": "./src/adapters/react.ts",
30
+ "node": "./dist/src/adapters/react.js",
31
+ "default": "./src/adapters/react.ts"
23
32
  },
24
33
  "./vue": {
25
34
  "types": "./dist/types/src/adapters/vue.d.ts",
26
- "default": "./dist/src/adapters/vue.js"
35
+ "bun": "./src/adapters/vue.ts",
36
+ "hamur-source": "./src/adapters/vue.ts",
37
+ "node": "./dist/src/adapters/vue.js",
38
+ "default": "./src/adapters/vue.ts"
27
39
  },
28
40
  "./preact": {
29
41
  "types": "./dist/types/src/adapters/preact.d.ts",
30
- "default": "./dist/src/adapters/preact.js"
42
+ "bun": "./src/adapters/preact.ts",
43
+ "hamur-source": "./src/adapters/preact.ts",
44
+ "node": "./dist/src/adapters/preact.js",
45
+ "default": "./src/adapters/preact.ts"
31
46
  },
32
47
  "./svelte": {
33
48
  "types": "./dist/types/src/adapters/svelte.d.ts",
34
- "default": "./dist/src/adapters/svelte.js"
49
+ "bun": "./src/adapters/svelte.ts",
50
+ "hamur-source": "./src/adapters/svelte.ts",
51
+ "node": "./dist/src/adapters/svelte.js",
52
+ "default": "./src/adapters/svelte.ts"
35
53
  },
36
54
  "./solid": {
37
55
  "types": "./dist/types/src/adapters/solid.d.ts",
38
- "default": "./dist/src/adapters/solid.js"
56
+ "bun": "./src/adapters/solid.ts",
57
+ "hamur-source": "./src/adapters/solid.ts",
58
+ "node": "./dist/src/adapters/solid.js",
59
+ "default": "./src/adapters/solid.ts"
39
60
  },
40
61
  "./html": {
41
62
  "types": "./dist/types/src/adapters/html.d.ts",
42
- "default": "./dist/src/adapters/html.js"
63
+ "bun": "./src/adapters/html.ts",
64
+ "hamur-source": "./src/adapters/html.ts",
65
+ "node": "./dist/src/adapters/html.js",
66
+ "default": "./src/adapters/html.ts"
43
67
  },
44
68
  "./angular": {
45
69
  "types": "./dist/types/src/adapters/angular.d.ts",
46
- "default": "./dist/src/adapters/angular.js"
70
+ "bun": "./src/adapters/angular.ts",
71
+ "hamur-source": "./src/adapters/angular.ts",
72
+ "node": "./dist/src/adapters/angular.js",
73
+ "default": "./src/adapters/angular.ts"
47
74
  },
48
75
  "./package.json": "./package.json"
49
76
  },
@@ -53,14 +80,14 @@
53
80
  ],
54
81
  "dependencies": {},
55
82
  "peerDependencies": {
56
- "hamur": "~0.0.1",
57
- "@hamur/adapter-react": "^0.0.1",
58
- "@hamur/adapter-vue": "^0.0.1",
59
- "@hamur/adapter-preact": "^0.0.1",
60
- "@hamur/adapter-svelte": "^0.0.1",
61
- "@hamur/adapter-solid": "^0.0.1",
62
- "@hamur/adapter-html": "^0.0.1",
63
- "@hamur/adapter-angular": "^0.0.1",
83
+ "hamur": "~0.0.2",
84
+ "@hamur/adapter-react": "^0.0.2",
85
+ "@hamur/adapter-vue": "^0.0.2",
86
+ "@hamur/adapter-preact": "^0.0.2",
87
+ "@hamur/adapter-svelte": "^0.0.2",
88
+ "@hamur/adapter-solid": "^0.0.2",
89
+ "@hamur/adapter-html": "^0.0.2",
90
+ "@hamur/adapter-angular": "^0.0.2",
64
91
  "react": "^19.3.1",
65
92
  "preact": "^11.0.2",
66
93
  "vue": "^3.5.44",
@@ -1,144 +1,143 @@
1
- import {
2
- Directive,
3
- ElementRef,
4
- Injector,
5
- Renderer2,
6
- DestroyRef,
7
- afterNextRender,
8
- booleanAttribute,
9
- computed,
10
- effect,
11
- inject,
12
- input,
13
- numberAttribute,
14
- runInInjectionContext,
15
- signal,
16
- type OnInit,
17
- } from "@angular/core"
18
- import type { ImageMeta } from "hamur"
19
- import { injectHead } from "@hamur/adapter-angular"
20
- import type { ImageFit, ImageFormat, ImageModifiers, HamurImagePreset, HamurImageProvider } from "../types.ts"
21
- import { imgAttributes } from "../runtime/index.ts"
22
- import { createImgEvents, imagePreloadLink, placeholderStyle } from "../runtime/img.ts"
23
-
24
- const optionalNumber = (value: unknown): number | undefined =>
25
- value === undefined ? undefined : numberAttribute(value)
26
-
1
+ import { Directive, ElementRef, Injector, Renderer2, DestroyRef, afterNextRender, booleanAttribute, computed, effect, inject, input, numberAttribute, runInInjectionContext, signal, } from "@angular/core";
2
+ import { injectHead } from "@hamur/adapter-angular";
3
+ import { imgAttributes } from "../runtime/index.ts";
4
+ import { createImgEvents, imagePreloadLink, placeholderStyle } from "../runtime/img.ts";
5
+ import * as i0 from "@angular/core";
6
+ const optionalNumber = (value) => value === undefined ? undefined : numberAttribute(value);
27
7
  /** An attribute binding takes a string, and `null` removes the attribute. */
28
- export const strings = (attributes: Record<string, unknown>): Record<string, string | null> =>
29
- Object.fromEntries(Object.entries(attributes).map(([name, value]) => [name, value == null ? null : String(value)]))
30
-
8
+ export const strings = (attributes) => Object.fromEntries(Object.entries(attributes).map(([name, value]) => [name, value == null ? null : String(value)]));
31
9
  /**
32
10
  * `<img hamurImg src="/hero.jpg" width="1200" alt="">`. The host bindings write what the other adapters' `Img`
33
11
  * writes on its `<img>`; every other attribute and listener stays the element's own. The props that are not attributes are
34
12
  * taken off the element. `src`, `srcset` and `sizes` are written only when they differ: the browser loads the image again on
35
13
  * every write, so a binding that rewrites the server's equal value during hydration fires `load` again.
36
14
  */
37
- @Directive({
38
- selector: "img[hamurImg]",
39
- host: {
40
- "[attr.hamurImg]": "null",
41
- "[attr.densities]": "null",
42
- "[attr.format]": "null",
43
- "[attr.quality]": "null",
44
- "[attr.fit]": "null",
45
- "[attr.modifiers]": "null",
46
- "[attr.provider]": "null",
47
- "[attr.preset]": "null",
48
- "[attr.preload]": "null",
49
- "[attr.placeholder]": "null",
50
- "[attr.placeholderClass]": "null",
51
- "[attr.width]": "attrs()['width']",
52
- "[attr.height]": "attrs()['height']",
53
- "[attr.alt]": "attrs()['alt']",
54
- "[attr.loading]": "attrs()['loading']",
55
- "[attr.decoding]": "attrs()['decoding']",
56
- "[attr.fetchpriority]": "attrs()['fetchpriority']",
57
- "[style]": "painted()",
58
- "[class]": "paintedClass()",
59
- },
60
- })
61
- export class Img implements OnInit {
62
- readonly src = input.required<string | ImageMeta>()
63
- readonly alt = input<string>()
64
- readonly width = input<number | string>()
65
- readonly height = input<number | string>()
66
- readonly sizes = input<string>()
67
- readonly densities = input<number[]>()
68
- readonly format = input<ImageFormat>()
69
- readonly quality = input<number | undefined, unknown>(undefined, { transform: optionalNumber })
70
- readonly fit = input<ImageFit>()
71
- readonly modifiers = input<ImageModifiers>()
72
- readonly provider = input<HamurImageProvider>()
73
- readonly preset = input<HamurImagePreset>()
74
- readonly loading = input<"lazy" | "eager">()
75
- readonly decoding = input<string>()
76
- readonly fetchpriority = input<"high" | "low" | "auto">()
77
- readonly preload = input(false, { transform: booleanAttribute })
78
- readonly placeholder = input<string>()
79
- readonly placeholderClass = input<string>()
80
-
81
- private readonly injector = inject(Injector)
82
- private readonly loaded = signal(false)
83
- private readonly events = createImgEvents(
84
- () => ({}),
85
- (value) => this.loaded.set(value),
86
- )
87
-
88
- private readonly resolved = computed(() =>
89
- imgAttributes({
90
- src: this.src(),
91
- alt: this.alt(),
92
- width: this.width(),
93
- height: this.height(),
94
- sizes: this.sizes(),
95
- densities: this.densities(),
96
- format: this.format(),
97
- quality: this.quality(),
98
- fit: this.fit(),
99
- modifiers: this.modifiers(),
100
- provider: this.provider(),
101
- preset: this.preset(),
102
- loading: this.loading(),
103
- decoding: this.decoding(),
104
- fetchpriority: this.fetchpriority(),
105
- preload: this.preload(),
106
- }),
107
- )
108
- protected readonly attrs = computed(() => strings(this.resolved()))
109
- protected readonly painted = computed(() => {
110
- const url = this.placeholder()
111
- return this.loaded() || !url ? {} : placeholderStyle(url)
112
- })
113
- protected readonly paintedClass = computed(() => (this.loaded() ? "" : (this.placeholderClass() ?? "")))
114
-
115
- constructor() {
116
- const element = inject<ElementRef<HTMLImageElement>>(ElementRef).nativeElement
117
- const renderer = inject(Renderer2)
118
- effect(() => {
119
- const attrs = this.attrs()
120
- for (const name of ["src", "srcset", "sizes"]) {
121
- const value = attrs[name] ?? null
122
- if (element.getAttribute(name) === value) continue
123
- if (value === null) renderer.removeAttribute(element, name)
124
- else renderer.setAttribute(element, name, value)
125
- }
126
- })
127
- // Read at hydration: a server image the browser already finished fired its load before any listener existed.
128
- const finished = element.isConnected && element.complete && element.getAttribute("src") !== null
129
- const offLoad = renderer.listen(element, "load", (event: Event) => this.events.load(event))
130
- const offError = renderer.listen(element, "error", (event: Event) => this.events.error(event))
131
- inject(DestroyRef).onDestroy(() => {
132
- offLoad()
133
- offError()
134
- })
135
- // Angular's event replay captures a load that fired before hydration and replays it to `(load)` bindings itself;
136
- // only the directive's own state is caught up here, so no second load is dispatched.
137
- if (finished) afterNextRender(() => this.loaded.set(element.naturalWidth > 0))
138
- }
139
-
140
- ngOnInit(): void {
141
- if (this.preload())
142
- runInInjectionContext(this.injector, () => injectHead(() => ({ link: [imagePreloadLink(this.resolved())] })))
143
- }
15
+ export class Img {
16
+ src = input.required(/* @ts-ignore */
17
+ ...(ngDevMode ? [{ debugName: "src" }] : /* istanbul ignore next */ []));
18
+ alt = input(/* @ts-ignore */
19
+ ...(ngDevMode ? [undefined, { debugName: "alt" }] : /* istanbul ignore next */ []));
20
+ width = input(/* @ts-ignore */
21
+ ...(ngDevMode ? [undefined, { debugName: "width" }] : /* istanbul ignore next */ []));
22
+ height = input(/* @ts-ignore */
23
+ ...(ngDevMode ? [undefined, { debugName: "height" }] : /* istanbul ignore next */ []));
24
+ sizes = input(/* @ts-ignore */
25
+ ...(ngDevMode ? [undefined, { debugName: "sizes" }] : /* istanbul ignore next */ []));
26
+ densities = input(/* @ts-ignore */
27
+ ...(ngDevMode ? [undefined, { debugName: "densities" }] : /* istanbul ignore next */ []));
28
+ format = input(/* @ts-ignore */
29
+ ...(ngDevMode ? [undefined, { debugName: "format" }] : /* istanbul ignore next */ []));
30
+ quality = input(undefined, { ...(ngDevMode ? { debugName: "quality" } : /* istanbul ignore next */ {}), transform: optionalNumber });
31
+ fit = input(/* @ts-ignore */
32
+ ...(ngDevMode ? [undefined, { debugName: "fit" }] : /* istanbul ignore next */ []));
33
+ modifiers = input(/* @ts-ignore */
34
+ ...(ngDevMode ? [undefined, { debugName: "modifiers" }] : /* istanbul ignore next */ []));
35
+ provider = input(/* @ts-ignore */
36
+ ...(ngDevMode ? [undefined, { debugName: "provider" }] : /* istanbul ignore next */ []));
37
+ preset = input(/* @ts-ignore */
38
+ ...(ngDevMode ? [undefined, { debugName: "preset" }] : /* istanbul ignore next */ []));
39
+ loading = input(/* @ts-ignore */
40
+ ...(ngDevMode ? [undefined, { debugName: "loading" }] : /* istanbul ignore next */ []));
41
+ decoding = input(/* @ts-ignore */
42
+ ...(ngDevMode ? [undefined, { debugName: "decoding" }] : /* istanbul ignore next */ []));
43
+ fetchpriority = input(/* @ts-ignore */
44
+ ...(ngDevMode ? [undefined, { debugName: "fetchpriority" }] : /* istanbul ignore next */ []));
45
+ preload = input(false, { ...(ngDevMode ? { debugName: "preload" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
46
+ placeholder = input(/* @ts-ignore */
47
+ ...(ngDevMode ? [undefined, { debugName: "placeholder" }] : /* istanbul ignore next */ []));
48
+ placeholderClass = input(/* @ts-ignore */
49
+ ...(ngDevMode ? [undefined, { debugName: "placeholderClass" }] : /* istanbul ignore next */ []));
50
+ injector = inject(Injector);
51
+ loaded = signal(false, /* @ts-ignore */
52
+ ...(ngDevMode ? [{ debugName: "loaded" }] : /* istanbul ignore next */ []));
53
+ events = createImgEvents(() => ({}), (value) => this.loaded.set(value));
54
+ resolved = computed(() => imgAttributes({
55
+ src: this.src(),
56
+ alt: this.alt(),
57
+ width: this.width(),
58
+ height: this.height(),
59
+ sizes: this.sizes(),
60
+ densities: this.densities(),
61
+ format: this.format(),
62
+ quality: this.quality(),
63
+ fit: this.fit(),
64
+ modifiers: this.modifiers(),
65
+ provider: this.provider(),
66
+ preset: this.preset(),
67
+ loading: this.loading(),
68
+ decoding: this.decoding(),
69
+ fetchpriority: this.fetchpriority(),
70
+ preload: this.preload(),
71
+ }), /* @ts-ignore */
72
+ ...(ngDevMode ? [{ debugName: "resolved" }] : /* istanbul ignore next */ []));
73
+ attrs = computed(() => strings(this.resolved()), /* @ts-ignore */
74
+ ...(ngDevMode ? [{ debugName: "attrs" }] : /* istanbul ignore next */ []));
75
+ painted = computed(() => {
76
+ const url = this.placeholder();
77
+ return this.loaded() || !url ? {} : placeholderStyle(url);
78
+ }, /* @ts-ignore */
79
+ ...(ngDevMode ? [{ debugName: "painted" }] : /* istanbul ignore next */ []));
80
+ paintedClass = computed(() => (this.loaded() ? "" : (this.placeholderClass() ?? "")), /* @ts-ignore */
81
+ ...(ngDevMode ? [{ debugName: "paintedClass" }] : /* istanbul ignore next */ []));
82
+ constructor() {
83
+ const element = inject(ElementRef).nativeElement;
84
+ const renderer = inject(Renderer2);
85
+ effect(() => {
86
+ const attrs = this.attrs();
87
+ for (const name of ["src", "srcset", "sizes"]) {
88
+ const value = attrs[name] ?? null;
89
+ if (element.getAttribute(name) === value)
90
+ continue;
91
+ if (value === null)
92
+ renderer.removeAttribute(element, name);
93
+ else
94
+ renderer.setAttribute(element, name, value);
95
+ }
96
+ });
97
+ // Read at hydration: a server image the browser already finished fired its load before any listener existed.
98
+ const finished = element.isConnected && element.complete && element.getAttribute("src") !== null;
99
+ const offLoad = renderer.listen(element, "load", (event) => this.events.load(event));
100
+ const offError = renderer.listen(element, "error", (event) => this.events.error(event));
101
+ inject(DestroyRef).onDestroy(() => {
102
+ offLoad();
103
+ offError();
104
+ });
105
+ // Angular's event replay captures a load that fired before hydration and replays it to `(load)` bindings itself;
106
+ // only the directive's own state is caught up here, so no second load is dispatched.
107
+ if (finished)
108
+ afterNextRender(() => this.loaded.set(element.naturalWidth > 0));
109
+ }
110
+ ngOnInit() {
111
+ if (this.preload())
112
+ runInInjectionContext(this.injector, () => injectHead(() => ({ link: [imagePreloadLink(this.resolved())] })));
113
+ }
114
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Img, deps: [], target: i0.ɵɵFactoryTarget.Directive });
115
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.3.2", type: Img, isStandalone: true, selector: "img[hamurImg]", inputs: { src: { classPropertyName: "src", publicName: "src", isSignal: true, isRequired: true, transformFunction: null }, alt: { classPropertyName: "alt", publicName: "alt", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, sizes: { classPropertyName: "sizes", publicName: "sizes", isSignal: true, isRequired: false, transformFunction: null }, densities: { classPropertyName: "densities", publicName: "densities", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, quality: { classPropertyName: "quality", publicName: "quality", isSignal: true, isRequired: false, transformFunction: null }, fit: { classPropertyName: "fit", publicName: "fit", isSignal: true, isRequired: false, transformFunction: null }, modifiers: { classPropertyName: "modifiers", publicName: "modifiers", isSignal: true, isRequired: false, transformFunction: null }, provider: { classPropertyName: "provider", publicName: "provider", isSignal: true, isRequired: false, transformFunction: null }, preset: { classPropertyName: "preset", publicName: "preset", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, decoding: { classPropertyName: "decoding", publicName: "decoding", isSignal: true, isRequired: false, transformFunction: null }, fetchpriority: { classPropertyName: "fetchpriority", publicName: "fetchpriority", isSignal: true, isRequired: false, transformFunction: null }, preload: { classPropertyName: "preload", publicName: "preload", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, placeholderClass: { classPropertyName: "placeholderClass", publicName: "placeholderClass", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.hamurImg": "null", "attr.densities": "null", "attr.format": "null", "attr.quality": "null", "attr.fit": "null", "attr.modifiers": "null", "attr.provider": "null", "attr.preset": "null", "attr.preload": "null", "attr.placeholder": "null", "attr.placeholderClass": "null", "attr.width": "attrs()['width']", "attr.height": "attrs()['height']", "attr.alt": "attrs()['alt']", "attr.loading": "attrs()['loading']", "attr.decoding": "attrs()['decoding']", "attr.fetchpriority": "attrs()['fetchpriority']", "style": "painted()", "class": "paintedClass()" } }, ngImport: i0 });
144
116
  }
117
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Img, decorators: [{
118
+ type: Directive,
119
+ args: [{
120
+ selector: "img[hamurImg]",
121
+ host: {
122
+ "[attr.hamurImg]": "null",
123
+ "[attr.densities]": "null",
124
+ "[attr.format]": "null",
125
+ "[attr.quality]": "null",
126
+ "[attr.fit]": "null",
127
+ "[attr.modifiers]": "null",
128
+ "[attr.provider]": "null",
129
+ "[attr.preset]": "null",
130
+ "[attr.preload]": "null",
131
+ "[attr.placeholder]": "null",
132
+ "[attr.placeholderClass]": "null",
133
+ "[attr.width]": "attrs()['width']",
134
+ "[attr.height]": "attrs()['height']",
135
+ "[attr.alt]": "attrs()['alt']",
136
+ "[attr.loading]": "attrs()['loading']",
137
+ "[attr.decoding]": "attrs()['decoding']",
138
+ "[attr.fetchpriority]": "attrs()['fetchpriority']",
139
+ "[style]": "painted()",
140
+ "[class]": "paintedClass()",
141
+ },
142
+ }]
143
+ }], ctorParameters: () => [], propDecorators: { src: [{ type: i0.Input, args: [{ isSignal: true, alias: "src", required: true }] }], alt: [{ type: i0.Input, args: [{ isSignal: true, alias: "alt", required: false }] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], sizes: [{ type: i0.Input, args: [{ isSignal: true, alias: "sizes", required: false }] }], densities: [{ type: i0.Input, args: [{ isSignal: true, alias: "densities", required: false }] }], format: [{ type: i0.Input, args: [{ isSignal: true, alias: "format", required: false }] }], quality: [{ type: i0.Input, args: [{ isSignal: true, alias: "quality", required: false }] }], fit: [{ type: i0.Input, args: [{ isSignal: true, alias: "fit", required: false }] }], modifiers: [{ type: i0.Input, args: [{ isSignal: true, alias: "modifiers", required: false }] }], provider: [{ type: i0.Input, args: [{ isSignal: true, alias: "provider", required: false }] }], preset: [{ type: i0.Input, args: [{ isSignal: true, alias: "preset", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], decoding: [{ type: i0.Input, args: [{ isSignal: true, alias: "decoding", required: false }] }], fetchpriority: [{ type: i0.Input, args: [{ isSignal: true, alias: "fetchpriority", required: false }] }], preload: [{ type: i0.Input, args: [{ isSignal: true, alias: "preload", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], placeholderClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholderClass", required: false }] }] } });
@@ -1,37 +1,97 @@
1
- import {
2
- Component,
3
- ElementRef,
4
- Injector,
5
- Renderer2,
6
- afterRenderEffect,
7
- booleanAttribute,
8
- computed,
9
- inject,
10
- input,
11
- numberAttribute,
12
- runInInjectionContext,
13
- signal,
14
- viewChild,
15
- type OnInit,
16
- } from "@angular/core"
17
- import type { ImageMeta } from "hamur"
18
- import { injectHead } from "@hamur/adapter-angular"
19
- import type { ImageFit, ImageFormat, ImageModifiers, HamurImagePreset, HamurImageProvider } from "../types.ts"
20
- import { pictureAttributes } from "../runtime/index.ts"
21
- import { applyPlaceholder, createImgEvents } from "../runtime/img.ts"
22
- import { picturePreloadLink } from "../runtime/picture.ts"
23
- import { strings } from "./angular-img.ts"
24
-
25
- const optionalNumber = (value: unknown): number | undefined =>
26
- value === undefined ? undefined : numberAttribute(value)
27
-
1
+ import { Component, Injector, Renderer2, afterRenderEffect, booleanAttribute, computed, inject, input, numberAttribute, runInInjectionContext, signal, viewChild, } from "@angular/core";
2
+ import { injectHead } from "@hamur/adapter-angular";
3
+ import { pictureAttributes } from "../runtime/index.ts";
4
+ import { applyPlaceholder, createImgEvents } from "../runtime/img.ts";
5
+ import { picturePreloadLink } from "../runtime/picture.ts";
6
+ import { strings } from "./angular-img.ts";
7
+ import * as i0 from "@angular/core";
8
+ const optionalNumber = (value) => value === undefined ? undefined : numberAttribute(value);
28
9
  /**
29
10
  * `<hamur-picture src="/hero.jpg" format="webp" width="1200" alt="" />`, one `<source>` per format and the
30
11
  * `<img>` in the source's own format, or the `<img>` alone when the provider makes no other format.
31
12
  */
32
- @Component({
33
- selector: "hamur-picture",
34
- template: `@if (parts().sources.length > 0) {
13
+ export class Picture {
14
+ src = input.required(/* @ts-ignore */
15
+ ...(ngDevMode ? [{ debugName: "src" }] : /* istanbul ignore next */ []));
16
+ alt = input(/* @ts-ignore */
17
+ ...(ngDevMode ? [undefined, { debugName: "alt" }] : /* istanbul ignore next */ []));
18
+ width = input(/* @ts-ignore */
19
+ ...(ngDevMode ? [undefined, { debugName: "width" }] : /* istanbul ignore next */ []));
20
+ height = input(/* @ts-ignore */
21
+ ...(ngDevMode ? [undefined, { debugName: "height" }] : /* istanbul ignore next */ []));
22
+ sizes = input(/* @ts-ignore */
23
+ ...(ngDevMode ? [undefined, { debugName: "sizes" }] : /* istanbul ignore next */ []));
24
+ densities = input(/* @ts-ignore */
25
+ ...(ngDevMode ? [undefined, { debugName: "densities" }] : /* istanbul ignore next */ []));
26
+ format = input(/* @ts-ignore */
27
+ ...(ngDevMode ? [undefined, { debugName: "format" }] : /* istanbul ignore next */ []));
28
+ legacyFormat = input(/* @ts-ignore */
29
+ ...(ngDevMode ? [undefined, { debugName: "legacyFormat" }] : /* istanbul ignore next */ []));
30
+ quality = input(undefined, { ...(ngDevMode ? { debugName: "quality" } : /* istanbul ignore next */ {}), transform: optionalNumber });
31
+ fit = input(/* @ts-ignore */
32
+ ...(ngDevMode ? [undefined, { debugName: "fit" }] : /* istanbul ignore next */ []));
33
+ modifiers = input(/* @ts-ignore */
34
+ ...(ngDevMode ? [undefined, { debugName: "modifiers" }] : /* istanbul ignore next */ []));
35
+ provider = input(/* @ts-ignore */
36
+ ...(ngDevMode ? [undefined, { debugName: "provider" }] : /* istanbul ignore next */ []));
37
+ preset = input(/* @ts-ignore */
38
+ ...(ngDevMode ? [undefined, { debugName: "preset" }] : /* istanbul ignore next */ []));
39
+ loading = input(/* @ts-ignore */
40
+ ...(ngDevMode ? [undefined, { debugName: "loading" }] : /* istanbul ignore next */ []));
41
+ decoding = input(/* @ts-ignore */
42
+ ...(ngDevMode ? [undefined, { debugName: "decoding" }] : /* istanbul ignore next */ []));
43
+ fetchpriority = input(/* @ts-ignore */
44
+ ...(ngDevMode ? [undefined, { debugName: "fetchpriority" }] : /* istanbul ignore next */ []));
45
+ preload = input(false, { ...(ngDevMode ? { debugName: "preload" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
46
+ placeholder = input(/* @ts-ignore */
47
+ ...(ngDevMode ? [undefined, { debugName: "placeholder" }] : /* istanbul ignore next */ []));
48
+ placeholderClass = input(/* @ts-ignore */
49
+ ...(ngDevMode ? [undefined, { debugName: "placeholderClass" }] : /* istanbul ignore next */ []));
50
+ injector = inject(Injector);
51
+ loaded = signal(false, /* @ts-ignore */
52
+ ...(ngDevMode ? [{ debugName: "loaded" }] : /* istanbul ignore next */ []));
53
+ element = viewChild("img", /* @ts-ignore */
54
+ ...(ngDevMode ? [{ debugName: "element" }] : /* istanbul ignore next */ []));
55
+ events = createImgEvents(() => ({}), (value) => this.loaded.set(value));
56
+ parts = computed(() => pictureAttributes({
57
+ src: this.src(),
58
+ alt: this.alt(),
59
+ width: this.width(),
60
+ height: this.height(),
61
+ sizes: this.sizes(),
62
+ densities: this.densities(),
63
+ format: this.format(),
64
+ legacyFormat: this.legacyFormat(),
65
+ quality: this.quality(),
66
+ fit: this.fit(),
67
+ modifiers: this.modifiers(),
68
+ provider: this.provider(),
69
+ preset: this.preset(),
70
+ loading: this.loading(),
71
+ decoding: this.decoding(),
72
+ fetchpriority: this.fetchpriority(),
73
+ preload: this.preload(),
74
+ }), /* @ts-ignore */
75
+ ...(ngDevMode ? [{ debugName: "parts" }] : /* istanbul ignore next */ []));
76
+ shown = computed(() => strings(applyPlaceholder(this.parts().img, { placeholder: this.placeholder(), placeholderClass: this.placeholderClass() }, this.loaded())), /* @ts-ignore */
77
+ ...(ngDevMode ? [{ debugName: "shown" }] : /* istanbul ignore next */ []));
78
+ constructor() {
79
+ const renderer = inject(Renderer2);
80
+ afterRenderEffect((onCleanup) => {
81
+ const image = this.element()?.nativeElement;
82
+ if (!image)
83
+ return;
84
+ onCleanup(renderer.listen(image, "load", (event) => this.events.load(event)));
85
+ onCleanup(renderer.listen(image, "error", (event) => this.events.error(event)));
86
+ this.events.replay(image);
87
+ });
88
+ }
89
+ ngOnInit() {
90
+ if (this.preload())
91
+ runInInjectionContext(this.injector, () => injectHead(() => ({ link: [picturePreloadLink(this.parts())] })));
92
+ }
93
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Picture, deps: [], target: i0.ɵɵFactoryTarget.Component });
94
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.2", type: Picture, isStandalone: true, selector: "hamur-picture", inputs: { src: { classPropertyName: "src", publicName: "src", isSignal: true, isRequired: true, transformFunction: null }, alt: { classPropertyName: "alt", publicName: "alt", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, sizes: { classPropertyName: "sizes", publicName: "sizes", isSignal: true, isRequired: false, transformFunction: null }, densities: { classPropertyName: "densities", publicName: "densities", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, legacyFormat: { classPropertyName: "legacyFormat", publicName: "legacyFormat", isSignal: true, isRequired: false, transformFunction: null }, quality: { classPropertyName: "quality", publicName: "quality", isSignal: true, isRequired: false, transformFunction: null }, fit: { classPropertyName: "fit", publicName: "fit", isSignal: true, isRequired: false, transformFunction: null }, modifiers: { classPropertyName: "modifiers", publicName: "modifiers", isSignal: true, isRequired: false, transformFunction: null }, provider: { classPropertyName: "provider", publicName: "provider", isSignal: true, isRequired: false, transformFunction: null }, preset: { classPropertyName: "preset", publicName: "preset", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, decoding: { classPropertyName: "decoding", publicName: "decoding", isSignal: true, isRequired: false, transformFunction: null }, fetchpriority: { classPropertyName: "fetchpriority", publicName: "fetchpriority", isSignal: true, isRequired: false, transformFunction: null }, preload: { classPropertyName: "preload", publicName: "preload", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, placeholderClass: { classPropertyName: "placeholderClass", publicName: "placeholderClass", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "element", first: true, predicate: ["img"], descendants: true, isSignal: true }], ngImport: i0, template: `@if (parts().sources.length > 0) {
35
95
  <picture>
36
96
  @for (source of parts().sources; track source.type) {
37
97
  <source [attr.type]="source.type" [attr.srcset]="source.srcset" [attr.sizes]="source.sizes" />
@@ -66,81 +126,47 @@ const optionalNumber = (value: unknown): number | undefined =>
66
126
  [attr.style]="shown()['style']"
67
127
  [attr.class]="shown()['class']"
68
128
  />
69
- }`,
70
- })
71
- export class Picture implements OnInit {
72
- readonly src = input.required<string | ImageMeta>()
73
- readonly alt = input<string>()
74
- readonly width = input<number | string>()
75
- readonly height = input<number | string>()
76
- readonly sizes = input<string>()
77
- readonly densities = input<number[]>()
78
- readonly format = input<ImageFormat | ImageFormat[]>()
79
- readonly legacyFormat = input<ImageFormat>()
80
- readonly quality = input<number | undefined, unknown>(undefined, { transform: optionalNumber })
81
- readonly fit = input<ImageFit>()
82
- readonly modifiers = input<ImageModifiers>()
83
- readonly provider = input<HamurImageProvider>()
84
- readonly preset = input<HamurImagePreset>()
85
- readonly loading = input<"lazy" | "eager">()
86
- readonly decoding = input<string>()
87
- readonly fetchpriority = input<"high" | "low" | "auto">()
88
- readonly preload = input(false, { transform: booleanAttribute })
89
- readonly placeholder = input<string>()
90
- readonly placeholderClass = input<string>()
91
-
92
- private readonly injector = inject(Injector)
93
- private readonly loaded = signal(false)
94
- private readonly element = viewChild<ElementRef<HTMLImageElement>>("img")
95
- private readonly events = createImgEvents(
96
- () => ({}),
97
- (value) => this.loaded.set(value),
98
- )
99
-
100
- protected readonly parts = computed(() =>
101
- pictureAttributes({
102
- src: this.src(),
103
- alt: this.alt(),
104
- width: this.width(),
105
- height: this.height(),
106
- sizes: this.sizes(),
107
- densities: this.densities(),
108
- format: this.format(),
109
- legacyFormat: this.legacyFormat(),
110
- quality: this.quality(),
111
- fit: this.fit(),
112
- modifiers: this.modifiers(),
113
- provider: this.provider(),
114
- preset: this.preset(),
115
- loading: this.loading(),
116
- decoding: this.decoding(),
117
- fetchpriority: this.fetchpriority(),
118
- preload: this.preload(),
119
- }),
120
- )
121
- protected readonly shown = computed(() =>
122
- strings(
123
- applyPlaceholder(
124
- this.parts().img,
125
- { placeholder: this.placeholder(), placeholderClass: this.placeholderClass() },
126
- this.loaded(),
127
- ),
128
- ),
129
- )
130
-
131
- constructor() {
132
- const renderer = inject(Renderer2)
133
- afterRenderEffect((onCleanup) => {
134
- const image = this.element()?.nativeElement
135
- if (!image) return
136
- onCleanup(renderer.listen(image, "load", (event: Event) => this.events.load(event)))
137
- onCleanup(renderer.listen(image, "error", (event: Event) => this.events.error(event)))
138
- this.events.replay(image)
139
- })
140
- }
141
-
142
- ngOnInit(): void {
143
- if (this.preload())
144
- runInInjectionContext(this.injector, () => injectHead(() => ({ link: [picturePreloadLink(this.parts())] })))
145
- }
129
+ }`, isInline: true });
146
130
  }
131
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Picture, decorators: [{
132
+ type: Component,
133
+ args: [{
134
+ selector: "hamur-picture",
135
+ template: `@if (parts().sources.length > 0) {
136
+ <picture>
137
+ @for (source of parts().sources; track source.type) {
138
+ <source [attr.type]="source.type" [attr.srcset]="source.srcset" [attr.sizes]="source.sizes" />
139
+ }
140
+ <img
141
+ #img
142
+ [attr.src]="shown()['src']"
143
+ [attr.srcset]="shown()['srcset']"
144
+ [attr.sizes]="shown()['sizes']"
145
+ [attr.width]="shown()['width']"
146
+ [attr.height]="shown()['height']"
147
+ [attr.alt]="shown()['alt']"
148
+ [attr.loading]="shown()['loading']"
149
+ [attr.decoding]="shown()['decoding']"
150
+ [attr.fetchpriority]="shown()['fetchpriority']"
151
+ [attr.style]="shown()['style']"
152
+ [attr.class]="shown()['class']"
153
+ />
154
+ </picture>
155
+ } @else {
156
+ <img
157
+ #img
158
+ [attr.src]="shown()['src']"
159
+ [attr.srcset]="shown()['srcset']"
160
+ [attr.sizes]="shown()['sizes']"
161
+ [attr.width]="shown()['width']"
162
+ [attr.height]="shown()['height']"
163
+ [attr.alt]="shown()['alt']"
164
+ [attr.loading]="shown()['loading']"
165
+ [attr.decoding]="shown()['decoding']"
166
+ [attr.fetchpriority]="shown()['fetchpriority']"
167
+ [attr.style]="shown()['style']"
168
+ [attr.class]="shown()['class']"
169
+ />
170
+ }`,
171
+ }]
172
+ }], ctorParameters: () => [], propDecorators: { src: [{ type: i0.Input, args: [{ isSignal: true, alias: "src", required: true }] }], alt: [{ type: i0.Input, args: [{ isSignal: true, alias: "alt", required: false }] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], sizes: [{ type: i0.Input, args: [{ isSignal: true, alias: "sizes", required: false }] }], densities: [{ type: i0.Input, args: [{ isSignal: true, alias: "densities", required: false }] }], format: [{ type: i0.Input, args: [{ isSignal: true, alias: "format", required: false }] }], legacyFormat: [{ type: i0.Input, args: [{ isSignal: true, alias: "legacyFormat", required: false }] }], quality: [{ type: i0.Input, args: [{ isSignal: true, alias: "quality", required: false }] }], fit: [{ type: i0.Input, args: [{ isSignal: true, alias: "fit", required: false }] }], modifiers: [{ type: i0.Input, args: [{ isSignal: true, alias: "modifiers", required: false }] }], provider: [{ type: i0.Input, args: [{ isSignal: true, alias: "provider", required: false }] }], preset: [{ type: i0.Input, args: [{ isSignal: true, alias: "preset", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], decoding: [{ type: i0.Input, args: [{ isSignal: true, alias: "decoding", required: false }] }], fetchpriority: [{ type: i0.Input, args: [{ isSignal: true, alias: "fetchpriority", required: false }] }], preload: [{ type: i0.Input, args: [{ isSignal: true, alias: "preload", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], placeholderClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholderClass", required: false }] }], element: [{ type: i0.ViewChild, args: ["img", { isSignal: true }] }] } });