@hamur/image 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.
package/dist/src/index.js CHANGED
@@ -66,7 +66,10 @@ ${blob}
66
66
  }
67
67
 
68
68
  // packages/image/src/build/platform.ts
69
- import { presetFeatures as presetFeatures2 } from "hamur/kit";
69
+ import { readdir } from "node:fs/promises";
70
+ import { join, sep } from "node:path";
71
+ import { DiagnosticError, presetFeatures as presetFeatures2 } from "hamur/kit";
72
+ import { accessRuleOf } from "hamur/server/internal";
70
73
 
71
74
  // packages/image/src/domains.ts
72
75
  var LABEL = "[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
@@ -122,6 +125,7 @@ function matchesDomain(matcher, url) {
122
125
 
123
126
  // packages/image/src/build/platform.ts
124
127
  var MIME = { avif: "image/avif", webp: "image/webp" };
128
+ var IMAGE_FILE = /\.(?:png|jpe?g|gif|webp|avif|svg)$/i;
125
129
  var MINIMUM_CACHE_TTL = 14400;
126
130
  var DEFAULT_QUALITY = 75;
127
131
  function remotePatterns({ domains, alias }) {
@@ -189,14 +193,24 @@ function setupPlatform(options, hamur) {
189
193
  return;
190
194
  const config = hamur.options[service].config;
191
195
  config.images = mergeImages(config.images, service === "vercel" ? vercelImages(options) : netlifyImages(options));
196
+ hamur.hooks.hook("prerender:done", async () => {
197
+ const files = await readdir(join(hamur.options.outputDir, "public"), { recursive: true }).catch(() => []);
198
+ const ruleOf = accessRuleOf(hamur.routeRules);
199
+ for (const file of files.filter((name) => IMAGE_FILE.test(name)).toSorted()) {
200
+ const path = `/${file.split(sep).map(encodeURIComponent).join("/")}`;
201
+ const found = ruleOf(path);
202
+ if (found)
203
+ throw new DiagnosticError("HAMUR_E6008", `Route rule ${JSON.stringify(found.pattern)} ${found.key} does not protect ${path}, which the ${service} image service reads itself; move the image out of public/ or set image.provider to "none"`);
204
+ }
205
+ });
192
206
  }
193
207
 
194
208
  // packages/image/src/build/runtime.ts
195
209
  import { createHash } from "node:crypto";
196
- import { readdir } from "node:fs/promises";
197
- import { join, relative, sep } from "node:path";
210
+ import { readdir as readdir2 } from "node:fs/promises";
211
+ import { join as join2, relative, sep as sep2 } from "node:path";
198
212
  import { addTemplate as addTemplate2, createResolver as createResolver2, diagnostic as diagnostic2, readImageMeta, useLogger as useLogger2 } from "hamur/kit";
199
- var IMAGE_FILE = /\.(png|jpe?g|gif|webp|avif|svg)$/i;
213
+ var IMAGE_FILE2 = /\.(png|jpe?g|gif|webp|avif|svg)$/i;
200
214
  var normalizedBase = (baseURL) => `${baseURL.replace(/\/+$/, "")}/`;
201
215
  function providerNames(options) {
202
216
  const names = new Set(["none", options.provider, ...Object.keys(options.providers)]);
@@ -208,10 +222,10 @@ function providerNames(options) {
208
222
  async function readSources(dirs, warn = () => {}) {
209
223
  const sources = {};
210
224
  for (const dir of dirs) {
211
- const entries = await readdir(dir, { recursive: true, withFileTypes: true }).catch(() => []);
212
- for (const entry of entries.filter((item) => item.isFile() && IMAGE_FILE.test(item.name)).sort((a, b) => join(a.parentPath, a.name).localeCompare(join(b.parentPath, b.name)))) {
213
- const file = join(entry.parentPath, entry.name);
214
- const key = `/${relative(dir, file).split(sep).join("/")}`;
225
+ const entries = await readdir2(dir, { recursive: true, withFileTypes: true }).catch(() => []);
226
+ for (const entry of entries.filter((item) => item.isFile() && IMAGE_FILE2.test(item.name)).sort((a, b) => join2(a.parentPath, a.name).localeCompare(join2(b.parentPath, b.name)))) {
227
+ const file = join2(entry.parentPath, entry.name);
228
+ const key = `/${relative(dir, file).split(sep2).join("/")}`;
215
229
  if (Object.hasOwn(sources, key))
216
230
  continue;
217
231
  if (key.includes(":")) {
@@ -320,7 +334,7 @@ function setupTypes(options) {
320
334
 
321
335
  // packages/image/src/build/variants.ts
322
336
  import { mkdir, readFile, writeFile } from "node:fs/promises";
323
- import { join as join2 } from "node:path";
337
+ import { join as join3 } from "node:path";
324
338
  import { emitPublicAsset, useLogger as useLogger3 } from "hamur/kit";
325
339
 
326
340
  // packages/image/src/server/endpoint.ts
@@ -605,6 +619,7 @@ var NOT_MADE = { gif: "GIF", svg: "SVG", avif: "AVIF", heic: "HEIC", tiff: "TIFF
605
619
  var SOURCE_FILE = /\.(?:png|jpe?g|gif|webp|avif|svg)$/i;
606
620
  var IMMUTABLE = "public, max-age=31536000, immutable";
607
621
  var HOUR = "public, max-age=3600";
622
+ var PRIVATE = "private, no-store";
608
623
  var REMOTE_TIMEOUT = 1e4;
609
624
  var REMOTE_CONNECT_TIMEOUT = 2500;
610
625
  var REMOTE_FRESH = 3600000;
@@ -863,7 +878,7 @@ ${got.tag}`, pinned: false, shown: url.href, load: async () => got.bytes };
863
878
  let bytes;
864
879
  return { tag: `${shown}@${entry[3]}`, width: entry[0], pinned, shown, load: async () => bytes ??= await read() };
865
880
  }
866
- async function produce(key, request, found) {
881
+ async function produce(key, request, found, guarded) {
867
882
  const bytes = await found.load();
868
883
  if (!bytes)
869
884
  return refuse(404, `source ${JSON.stringify(found.shown)} not found`);
@@ -878,6 +893,8 @@ ${got.tag}`, pinned: false, shown: url.href, load: async () => got.bytes };
878
893
  } catch (error) {
879
894
  return refusalOf(error);
880
895
  }
896
+ if (guarded)
897
+ return output;
881
898
  try {
882
899
  await env.cache().setItemRaw(key, output);
883
900
  } catch (error) {
@@ -888,10 +905,10 @@ ${got.tag}`, pinned: false, shown: url.href, load: async () => got.bytes };
888
905
  }
889
906
  return output;
890
907
  }
891
- async function answerFound(parsed, found, incoming, head) {
908
+ async function answerFound(parsed, found, incoming, head, guarded) {
892
909
  const again = async (reread) => {
893
910
  const fresh = await reread();
894
- return isRefusal(fresh) ? answerText(fresh, head) : answerFound(parsed, fresh, incoming, head);
911
+ return isRefusal(fresh) ? answerText(fresh, head) : answerFound(parsed, fresh, incoming, head, guarded);
895
912
  };
896
913
  if (parsed.w !== undefined && !options.widths.includes(parsed.w)) {
897
914
  if (found.width === undefined && found.reread)
@@ -918,18 +935,18 @@ ${parsed.extension}`))).slice(0, 16)}`;
918
935
  const headers = {
919
936
  "content-type": TYPES[parsed.extension],
920
937
  etag,
921
- "cache-control": endpoint.dev ? "no-cache" : found.pinned ? IMMUTABLE : HOUR,
938
+ "cache-control": guarded ? PRIVATE : endpoint.dev ? "no-cache" : found.pinned ? IMMUTABLE : HOUR,
922
939
  "x-content-type-options": "nosniff"
923
940
  };
924
941
  if (matchesTag(incoming.headers.get("if-none-match"), etag))
925
942
  return new Response(null, { status: 304, headers });
926
- let output = await env.cache().getItemRaw(key);
943
+ let output = guarded ? undefined : await env.cache().getItemRaw(key);
927
944
  if (!output && found.reread)
928
945
  return again(found.reread);
929
946
  if (!output) {
930
947
  let work = running.get(key);
931
948
  if (work === undefined) {
932
- work = produce(key, parsed, found).finally(() => running.delete(key));
949
+ work = produce(key, parsed, found, guarded).finally(() => running.delete(key));
933
950
  running.set(key, work);
934
951
  }
935
952
  output = await work;
@@ -938,21 +955,23 @@ ${parsed.extension}`))).slice(0, 16)}`;
938
955
  return answerText(output, head);
939
956
  return new Response(head ? null : owned(output), { status: 200, headers });
940
957
  }
941
- return async (incoming) => {
958
+ return async (incoming, access) => {
942
959
  const head = incoming.method === "HEAD";
943
960
  const { pathname, search } = new URL(incoming.url);
944
961
  const parsed = pathname.startsWith(prefix) ? parseImagePath(pathname.slice(prefix.length)) : refuse(404, "not found");
945
962
  if (isRefusal(parsed))
946
963
  return answerText(parsed, head);
964
+ const guarded = parsed.path !== undefined && access !== undefined && await access(`/${parsed.path.split("/").map(encodeURIComponent).join("/")}`);
947
965
  const found = parsed.remote === undefined ? await findLocal(parsed) : await findRemote(parsed.remote, search);
948
966
  if (isRefusal(found))
949
967
  return answerText(found, head);
950
- return answerFound(parsed, found, incoming, head);
968
+ return answerFound(parsed, found, incoming, head, guarded);
951
969
  };
952
970
  }
953
971
 
954
972
  // packages/image/src/build/variants.ts
955
- import { DiagnosticError } from "hamur/kit";
973
+ import { DiagnosticError as DiagnosticError2 } from "hamur/kit";
974
+ import { accessRuleOf as accessRuleOf2, hasPlatformFiles } from "hamur/server/internal";
956
975
  var ATTRIBUTE = /\s(src|srcset|imagesrcset|href|style)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi;
957
976
  var STYLE_URL = /url\(\s*(?:"([^"]*)"|'([^']*)'|([^)\s]*))\s*\)/gi;
958
977
  var ENTITY = /&(?:#(\d+)|#x([0-9a-f]+)|(amp|quot|apos|lt|gt));/gi;
@@ -994,7 +1013,7 @@ function sourceUrls(path, entry, options, baseURL) {
994
1013
  return widths.flatMap((width) => extensions.map((extension) => `${baseURL}_hamur/image/${modifiers(width)}/${path.split("/").map(encodeURIComponent).join("/")}.${extension}`));
995
1014
  }
996
1015
  function fileCache(dir, onWrite) {
997
- const file = (key) => join2(dir, key.replace(/[^a-z0-9-]/gi, "-"));
1016
+ const file = (key) => join3(dir, key.replace(/[^a-z0-9-]/gi, "-"));
998
1017
  return {
999
1018
  async getItemRaw(key) {
1000
1019
  try {
@@ -1039,7 +1058,7 @@ function setupVariants(options, hamur) {
1039
1058
  const path = entry.slice(1);
1040
1059
  const matched = Object.entries(sources).filter(([key, source]) => !source[4] && TRANSFORMABLE.test(key) && new Bun.Glob(path).match(key.slice(1)));
1041
1060
  if (!matched.length && !isGlob(path))
1042
- throw new DiagnosticError("HAMUR_E6003", `image: image.prerender ${JSON.stringify(entry)}: source ${JSON.stringify(entry)} not found`);
1061
+ throw new DiagnosticError2("HAMUR_E6003", `image: image.prerender ${JSON.stringify(entry)}: source ${JSON.stringify(entry)} not found`);
1043
1062
  for (const [key, source] of matched)
1044
1063
  for (const url of sourceUrls(key.slice(1), source, options, baseURL))
1045
1064
  if (!where.has(url))
@@ -1047,10 +1066,22 @@ function setupVariants(options, hamur) {
1047
1066
  }
1048
1067
  if (!where.size)
1049
1068
  return;
1069
+ const ruleOf = accessRuleOf2(hamur.routeRules);
1070
+ const alone = hasPlatformFiles(hamur);
1071
+ for (const url of where.keys()) {
1072
+ const variant = new URL(url, "http://localhost").pathname;
1073
+ const parsed = parseImagePath(variant.slice(prefix.length));
1074
+ if (isRefusal(parsed) || parsed.path === undefined)
1075
+ continue;
1076
+ const source = `/${parsed.path.split("/").map(encodeURIComponent).join("/")}`;
1077
+ const found = ruleOf(source, alone ? undefined : `/${variant.slice(baseURL.length)}`);
1078
+ if (found)
1079
+ throw new DiagnosticError2("HAMUR_E6008", `Route rule ${JSON.stringify(found.pattern)} ${found.key} does not protect the variants of ${source} (in ${where.get(url)}), which are public files; use the "none" provider for this image`);
1080
+ }
1050
1081
  Bun.Image.backend = "bun";
1051
1082
  let created = 0;
1052
- const cache = fileCache(join2(hamur.options.rootDir, "node_modules/.cache/hamur/image"), () => created++);
1053
- const publicDir = join2(hamur.options.outputDir, "public");
1083
+ const cache = fileCache(join3(hamur.options.rootDir, "node_modules/.cache/hamur/image"), () => created++);
1084
+ const publicDir = join3(hamur.options.outputDir, "public");
1054
1085
  const answer = createImageEndpoint({
1055
1086
  options: { baseURL, widths: options.widths, domains: options.domains, alias: options.alias },
1056
1087
  sources,
@@ -1064,7 +1095,7 @@ function setupVariants(options, hamur) {
1064
1095
  },
1065
1096
  readSource: readFromDirs(options.dirs),
1066
1097
  readAsset: async (path) => {
1067
- const file = Bun.file(join2(publicDir, path));
1098
+ const file = Bun.file(join3(publicDir, path));
1068
1099
  return await file.exists() ? file.bytes() : undefined;
1069
1100
  },
1070
1101
  cache: () => cache,
@@ -1092,7 +1123,7 @@ function setupVariants(options, hamur) {
1092
1123
  await Promise.all(Array.from({ length: Math.min(CONCURRENCY, urls.length) }, work));
1093
1124
  const failed = failures.find((message) => message !== undefined);
1094
1125
  if (failed !== undefined)
1095
- throw new DiagnosticError("HAMUR_E6004", failed);
1126
+ throw new DiagnosticError2("HAMUR_E6004", failed);
1096
1127
  urls.forEach((url, i) => emitPublicAsset(`/${new URL(url, "http://localhost").pathname.slice(baseURL.length)}`, bytes[i]));
1097
1128
  log.info(`[image] ${urls.length} variants (${created} new, ${urls.length - created} from cache)`);
1098
1129
  });
@@ -1100,7 +1131,7 @@ function setupVariants(options, hamur) {
1100
1131
 
1101
1132
  // packages/image/src/options.ts
1102
1133
  import { resolve } from "node:path";
1103
- import { DiagnosticError as DiagnosticError2 } from "hamur/kit";
1134
+ import { DiagnosticError as DiagnosticError3 } from "hamur/kit";
1104
1135
  var BUILT_IN_PROVIDERS = [
1105
1136
  "hamur",
1106
1137
  "none",
@@ -1152,7 +1183,7 @@ var SECRET_OPTIONS = ["key", "secret", "salt"];
1152
1183
  var MAX_WIDTH = 16384;
1153
1184
  var SCREEN_NAME = /^[a-z0-9]+$/i;
1154
1185
  function fail(message) {
1155
- throw new DiagnosticError2("HAMUR_E6001", message);
1186
+ throw new DiagnosticError3("HAMUR_E6001", message);
1156
1187
  }
1157
1188
  function shown(value) {
1158
1189
  if (Array.isArray(value))
@@ -1418,7 +1449,7 @@ function resolveOptions(input, env) {
1418
1449
  }
1419
1450
 
1420
1451
  // packages/image/src/module.ts
1421
- import { DiagnosticError as DiagnosticError3 } from "hamur/kit";
1452
+ import { DiagnosticError as DiagnosticError4 } from "hamur/kit";
1422
1453
  var module_default = defineModule({
1423
1454
  meta: { name: "image", configKey: "image" },
1424
1455
  async setup(input, hamur) {
@@ -1429,7 +1460,7 @@ var module_default = defineModule({
1429
1460
  });
1430
1461
  const options = { ...resolved, provider: resolveProvider(resolved.provider, hamur) };
1431
1462
  if (options.sources.blob && !hasModule("@hamur/blob"))
1432
- throw new DiagnosticError3("HAMUR_E6002", 'image.sources.blob needs "@hamur/blob" in modules');
1463
+ throw new DiagnosticError4("HAMUR_E6002", 'image.sources.blob needs "@hamur/blob" in modules');
1433
1464
  setupRuntime(options, hamur);
1434
1465
  setupEndpoint(options, hamur);
1435
1466
  setupVariants(options, hamur);
@@ -0,0 +1,33 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+ import type { HTMLImgAttributes } from "svelte/elements"
4
+ import { useHead } from "@hamur/adapter-svelte"
5
+ import { imgAttributes } from "../runtime/index.ts"
6
+ import { applyPlaceholder, imagePreloadLink, type ImgOptions, type ImgState } from "../runtime/img.ts"
7
+
8
+ type Props = ImgOptions & {
9
+ fetchpriority?: "high" | "low" | "auto"
10
+ children?: Snippet<[ImgState]>
11
+ } & Omit<HTMLImgAttributes, keyof ImgOptions | "srcset" | "fetchpriority" | "children">
12
+
13
+ let { children, onload, onerror, ...props }: Props = $props()
14
+ let isLoaded = $state(false)
15
+ if (props.preload) useHead(() => ({ link: [imagePreloadLink(imgAttributes(props))] }))
16
+ const attrs = $derived({
17
+ ...applyPlaceholder(imgAttributes(props), props, isLoaded),
18
+ onload: (event: Event) => {
19
+ isLoaded = true
20
+ ;(onload as ((event: Event) => void) | null | undefined)?.(event)
21
+ },
22
+ onerror: (event: Event) => {
23
+ isLoaded = false
24
+ ;(onerror as ((event: Event) => void) | null | undefined)?.(event)
25
+ },
26
+ })
27
+ </script>
28
+
29
+ {#if children}
30
+ {@render children({ imgAttrs: attrs, src: String(attrs.src), isLoaded })}
31
+ {:else}
32
+ <img {...attrs} />
33
+ {/if}
@@ -0,0 +1,39 @@
1
+ <script lang="ts">
2
+ import type { HTMLImgAttributes } from "svelte/elements"
3
+ import { useHead } from "@hamur/adapter-svelte"
4
+ import { pictureAttributes } from "../runtime/index.ts"
5
+ import { applyPlaceholder } from "../runtime/img.ts"
6
+ import { picturePreloadLink, type PictureOptions } from "../runtime/picture.ts"
7
+
8
+ type Props = PictureOptions & { fetchpriority?: "high" | "low" | "auto" } & Omit<
9
+ HTMLImgAttributes,
10
+ keyof PictureOptions | "srcset" | "fetchpriority"
11
+ >
12
+
13
+ let { onload, onerror, ...props }: Props = $props()
14
+ let isLoaded = $state(false)
15
+ const parts = $derived(pictureAttributes(props))
16
+ const img = $derived({
17
+ ...applyPlaceholder(parts.img, props, isLoaded),
18
+ onload: (event: Event) => {
19
+ isLoaded = true
20
+ ;(onload as ((event: Event) => void) | null | undefined)?.(event)
21
+ },
22
+ onerror: (event: Event) => {
23
+ isLoaded = false
24
+ ;(onerror as ((event: Event) => void) | null | undefined)?.(event)
25
+ },
26
+ })
27
+ if (props.preload) useHead(() => ({ link: [picturePreloadLink(parts)] }))
28
+ </script>
29
+
30
+ {#if parts.sources.length === 0}
31
+ <img {...img} />
32
+ {:else}
33
+ <picture>
34
+ {#each parts.sources as source (source.type)}
35
+ <source {...source} />
36
+ {/each}
37
+ <img {...img} />
38
+ </picture>
39
+ {/if}
@@ -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
  }
@@ -42,5 +42,7 @@ export declare function readFromDirs(dirs: readonly string[]): (path: string) =>
42
42
  export declare function checkSource(bytes: Uint8Array, maxPixels: number): SourceSize | ImageRefusal;
43
43
  /** With `Bun.Image`: `rot`, `flip`, `flop`, then the resize, then the encoder of the extension. */
44
44
  export declare const transformImage: ImageTransform;
45
- /** The `/_hamur/image/**` answer. Every 200 is bytes this endpoint encoded, never a source's own. */
46
- export declare function createImageEndpoint(env: EndpointEnvironment): (request: Request) => Promise<Response>;
45
+ /** Throws the refusal of the access rule on the public file at `path`; true when a rule covers it. */
46
+ export type SourceAccess = (path: string) => Promise<boolean>;
47
+ /** The `/_hamur/image/**` answer. Every 200 is bytes this endpoint encoded, never a source's own. An image has the access of its source. */
48
+ export declare function createImageEndpoint(env: EndpointEnvironment): (request: Request, access?: SourceAccess) => Promise<Response>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamur/image",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
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.3",
84
+ "@hamur/adapter-react": "^0.0.3",
85
+ "@hamur/adapter-vue": "^0.0.3",
86
+ "@hamur/adapter-preact": "^0.0.3",
87
+ "@hamur/adapter-svelte": "^0.0.3",
88
+ "@hamur/adapter-solid": "^0.0.3",
89
+ "@hamur/adapter-html": "^0.0.3",
90
+ "@hamur/adapter-angular": "^0.0.3",
64
91
  "react": "^19.3.1",
65
92
  "preact": "^11.0.2",
66
93
  "vue": "^3.5.44",