veyce 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/react.tsx","../src/index.ts"],"sourcesContent":["import { createContext, useContext, useMemo, type ImgHTMLAttributes, type ReactNode } from \"react\";\nimport {\n avatarSrcSet,\n avatarUrl,\n clampSize,\n DEFAULT_SIZE,\n type AvatarOptions,\n} from \"./index\";\n\ntype ProviderValue = { baseUrl?: string; defaults?: AvatarOptions };\n\nconst AvatarContext = createContext<ProviderValue | null>(null);\n\n/** Set the service URL (defaults to https://veyce.vercel.app) and shared defaults once for every `<Avatar>` below. */\nexport function AvatarProvider({\n baseUrl,\n defaults,\n children,\n}: ProviderValue & { children?: ReactNode }) {\n const value = useMemo(() => ({ baseUrl, defaults }), [baseUrl, defaults]);\n return <AvatarContext.Provider value={value}>{children}</AvatarContext.Provider>;\n}\n\nexport type AvatarProps = AvatarOptions &\n Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"srcSet\" | \"id\" | \"crossOrigin\"> & {\n /** Overrides the provider's `baseUrl`. */\n baseUrl?: string;\n /** Emit a 1x/2x/3x `srcSet`. Defaults to true. */\n hiDpi?: boolean;\n /** The `id` HTML attribute (`id` itself is the image id). */\n htmlId?: string;\n };\n\n/**\n * `<Avatar seed=\"ada@example.com\" size={48} />`\n *\n * Renders a plain `<img>` with width/height set (no layout shift), lazy loading\n * and a high-density `srcSet`.\n */\nexport function Avatar({\n baseUrl,\n collection,\n id,\n seed,\n size,\n crop,\n fit,\n square,\n format,\n background,\n hiDpi = true,\n htmlId,\n alt = \"\",\n loading = \"lazy\",\n decoding = \"async\",\n ...img\n}: AvatarProps) {\n const context = useContext(AvatarContext);\n const base = baseUrl ?? context?.baseUrl;\n\n const own: AvatarOptions = { collection, id, seed, size, crop, fit, square, format, background };\n for (const key of Object.keys(own) as (keyof AvatarOptions)[]) {\n if (own[key] === undefined) delete own[key];\n }\n const options: AvatarOptions = { ...context?.defaults, ...own };\n const px = clampSize(options.size ?? DEFAULT_SIZE);\n\n return (\n // A plain <img> on purpose: the service already resizes and encodes.\n // eslint-disable-next-line @next/next/no-img-element\n <img\n {...img}\n id={htmlId}\n src={avatarUrl(base, { ...options, size: px })}\n srcSet={hiDpi ? avatarSrcSet(base, { ...options, size: px }) : undefined}\n width={img.width ?? px}\n height={img.height ?? px}\n alt={alt}\n loading={loading}\n decoding={decoding}\n />\n );\n}\n\n/** Hook form: `const src = useAvatarUrl({ seed: user.email, size: 64 })`. */\nexport function useAvatarUrl(options: AvatarOptions & { baseUrl?: string } = {}): string {\n const context = useContext(AvatarContext);\n const { baseUrl, ...rest } = options;\n const base = baseUrl ?? context?.baseUrl;\n return avatarUrl(base, { ...context?.defaults, ...rest });\n}\n\nexport type { AvatarOptions } from \"./index\";\n","/**\n * veyce — a tiny, dependency-free client for the avatars API.\n *\n * const avatars = createAvatars(); // uses https://veyce.vercel.app\n *\n * avatars.url({ seed: \"ada@example.com\", size: 96 }); // any string -> always an avatar\n * avatars.url({ id: \"raul\", collection: \"gta-vi\" }); // exact id -> that image, or 404\n * avatars.url({ id: user.avatarId, seed: user.email }); // exact if it exists, seed otherwise\n *\n * Works in browsers, Node 18+, Deno, Bun and edge runtimes.\n */\n\n/** The public veyce service. Used whenever no `baseUrl` is given. */\nexport const DEFAULT_BASE_URL = \"https://veyce.vercel.app\";\n\nexport const MIN_SIZE = 8;\nexport const MAX_SIZE = 2160;\nexport const DEFAULT_SIZE = 80;\n\nexport const CROPS = [\"square\", \"portrait\", \"landscape\", \"phone\", \"tablet\", \"ultrawide\"] as const;\nexport type Crop = (typeof CROPS)[number];\n\nexport const FORMATS = [\"webp\", \"png\", \"jpeg\"] as const;\nexport type Format = (typeof FORMATS)[number];\n\nexport type AvatarOptions = {\n /** Collection to draw from, e.g. `gta-vi`. Omit to use every collection. */\n collection?: string;\n /**\n * Exact image id. Unknown ids are a 404 — unless a `seed` is also given, in\n * which case the API falls back to the seed.\n */\n id?: string;\n /**\n * Anything: an email, username, uuid, number. The same seed always maps to\n * the same image (for a fixed library). Never 404s.\n */\n seed?: string | number;\n /** Pixels, 8–2160. Defaults to 80. Never upscaled past the source image. */\n size?: number;\n /** Which crop of the image to use. Defaults to `square`. */\n crop?: Crop | (string & {});\n /** `full` keeps the original aspect ratio (no mask). Defaults to `cover`. */\n fit?: \"cover\" | \"full\";\n /** Square corners instead of the default circle mask. */\n square?: boolean;\n /** Output format. Defaults to `webp`. */\n format?: Format;\n /** Hex corner fill used when a circle is encoded as JPEG, e.g. `#0b0b0f`. */\n background?: string;\n};\n\nexport type ClientConfig = {\n /** Where the avatars service is hosted. Defaults to `https://veyce.vercel.app`. A trailing `/api` is fine. */\n baseUrl?: string;\n /** Options applied to every call; per-call options win. */\n defaults?: AvatarOptions;\n /** Custom fetch (for tests, proxies or older runtimes). Defaults to `globalThis.fetch`. */\n fetch?: typeof fetch;\n};\n\n/** How the API chose the image. */\nexport type Match = \"id\" | \"seed\" | \"random\";\n\nexport type AvatarInfo = {\n collection: string;\n id: string;\n crop: string;\n /** The real pixel size served (may be smaller than requested). */\n size: number;\n match: Match;\n /** Stable URL that addresses this exact image by id — store this to \"pin\" a seeded avatar. */\n url: string;\n};\n\nexport type Photo = {\n id: string;\n label: string;\n collection: string;\n crops: string[];\n /** Path on the service, e.g. `/api/gta-vi/raul`. */\n url: string;\n};\n\nexport type PhotoIndex = {\n count: number;\n collections: string[];\n size: { min: number; max: number; default: number };\n photos: Photo[];\n};\n\nexport type AvatarImage = {\n bytes: Uint8Array;\n contentType: string;\n info: AvatarInfo;\n};\n\nexport class AvatarError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body?: unknown) {\n super(message);\n this.name = \"AvatarError\";\n this.status = status;\n this.body = body;\n }\n}\n\n/**\n * The seed hash the service uses. Exposed so you can map seeds to images\n * offline (see `pick`) and get the exact same answer as the API.\n */\nexport function hashSeed(seed: string | number): number {\n const value = String(seed);\n let hash = 0;\n for (let i = 0; i < value.length; i += 1) {\n hash = (hash << 5) - hash + value.charCodeAt(i);\n hash |= 0;\n }\n return Math.abs(hash) || 1;\n}\n\n/**\n * Offline seed -> photo, identical to the API's choice for the same library.\n * Pass `photos` from `list()` (scoped to the same collection you pass the API).\n */\nexport function pick<T>(seed: string | number, photos: readonly T[]): T | undefined {\n if (!photos.length) return undefined;\n return photos[hashSeed(seed) % photos.length];\n}\n\nexport function clampSize(size: number): number {\n if (!Number.isFinite(size)) return DEFAULT_SIZE;\n return Math.min(MAX_SIZE, Math.max(MIN_SIZE, Math.round(size)));\n}\n\n/** `https://x.com/`, `https://x.com/api` -> `https://x.com/api` */\nfunction apiRoot(baseUrl?: string): string {\n const trimmed = (baseUrl || DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n return /\\/api$/.test(trimmed) ? trimmed : `${trimmed}/api`;\n}\n\nfunction normalizeHex(value: string): string | null {\n const hex = value.replace(/^#/, \"\");\n return /^([0-9a-f]{3}|[0-9a-f]{6})$/i.test(hex) ? hex.toLowerCase() : null;\n}\n\n/**\n * Build an avatar URL. Pure string work — no network, safe to call in render.\n *\n * Ids and seeds always go in the query string, so a seed that happens to look\n * like an id, a size or a crop is never misread.\n */\nexport function avatarUrl(baseUrl: string | undefined, options: AvatarOptions = {}): string {\n const root = apiRoot(baseUrl);\n const path = options.collection ? `${root}/${encodeURIComponent(options.collection)}` : root;\n\n const query = new URLSearchParams();\n if (options.id !== undefined && options.id !== \"\") query.set(\"id\", options.id);\n if (options.seed !== undefined && options.seed !== \"\") query.set(\"seed\", String(options.seed));\n if (options.size !== undefined) query.set(\"size\", String(clampSize(options.size)));\n if (options.crop) query.set(\"crop\", options.crop);\n if (options.fit && options.fit !== \"cover\") query.set(\"fit\", options.fit);\n if (options.square) query.set(\"square\", \"true\");\n if (options.format && options.format !== \"webp\") query.set(\"format\", options.format);\n if (options.background) {\n const hex = normalizeHex(options.background);\n if (!hex) throw new TypeError(`veyce: invalid background \"${options.background}\".`);\n query.set(\"bg\", hex);\n }\n\n const qs = query.toString();\n return qs ? `${path}?${qs}` : path;\n}\n\n/** `url 1x, url 2x, url 3x` for crisp avatars on high-density screens. */\nexport function avatarSrcSet(\n baseUrl: string | undefined,\n options: AvatarOptions = {},\n densities: readonly number[] = [1, 2, 3],\n): string {\n const size = options.size ?? DEFAULT_SIZE;\n const seen = new Set<number>();\n return densities\n .map((density) => ({ density, px: clampSize(size * density) }))\n .filter(({ px }) => (seen.has(px) ? false : (seen.add(px), true)))\n .map(({ density, px }) => `${avatarUrl(baseUrl, { ...options, size: px })} ${density}x`)\n .join(\", \");\n}\n\nfunction readInfo(root: string, headers: Headers, requested: number): AvatarInfo {\n const collection = headers.get(\"x-photo-collection\") ?? \"\";\n const id = headers.get(\"x-photo-id\") ?? \"\";\n const match = (headers.get(\"x-photo-match\") as Match | null) ?? \"id\";\n return {\n collection,\n id,\n crop: headers.get(\"x-photo-crop\") ?? \"square\",\n size: Number(headers.get(\"x-photo-size\") ?? requested),\n match,\n url: avatarUrl(root, { collection, id }),\n };\n}\n\nasync function fail(response: Response): Promise<never> {\n let body: unknown;\n let message =\n response.status === 404\n ? \"veyce: no image matches (unknown id or collection) — pass a `seed` to always get one\"\n : response.status === 409\n ? \"veyce: that id exists in several collections — pass `collection`\"\n : `veyce: request failed with ${response.status}`;\n try {\n body = await response.json();\n const error = (body as { error?: unknown })?.error;\n if (typeof error === \"string\") message = `veyce: ${error}`;\n } catch {\n // not JSON — keep the generic message\n }\n throw new AvatarError(message, response.status, body);\n}\n\nfunction toBase64(bytes: Uint8Array): string {\n const B = (globalThis as { Buffer?: { from(b: Uint8Array): { toString(enc: string): string } } })\n .Buffer;\n if (B) return B.from(bytes).toString(\"base64\");\n let binary = \"\";\n for (let i = 0; i < bytes.length; i += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));\n }\n return btoa(binary);\n}\n\nexport type AvatarClient = {\n readonly baseUrl: string;\n /** Avatar URL for an `<img src>`. No network. */\n url(options?: AvatarOptions): string;\n /** `srcset` value with 1x/2x/3x variants. No network. */\n srcSet(options?: AvatarOptions, densities?: readonly number[]): string;\n /** Download the image bytes (plus which image it was). */\n fetch(options?: AvatarOptions): Promise<AvatarImage>;\n /** Download as a `data:` URI — handy for emails, canvases and offline storage. */\n dataUri(options?: AvatarOptions): Promise<string>;\n /** Ask which image a request lands on, without downloading it (HEAD). */\n resolve(options?: AvatarOptions): Promise<AvatarInfo>;\n /** The library index: every collection and id. */\n list(collection?: string): Promise<PhotoIndex>;\n /** Offline seed -> photo, using an index you already fetched with `list()`. */\n pick(seed: string | number, index: PhotoIndex | readonly Photo[]): Photo | undefined;\n};\n\nexport function createAvatars(config: ClientConfig = {}): AvatarClient {\n const root = apiRoot(config.baseUrl);\n const defaults = config.defaults ?? {};\n const doFetch = (input: string, init?: RequestInit) => {\n const f = config.fetch ?? globalThis.fetch;\n if (!f) throw new Error(\"veyce: no global fetch; pass `fetch` in the config.\");\n return f(input, init);\n };\n const merge = (options?: AvatarOptions): AvatarOptions => ({ ...defaults, ...options });\n\n const client: AvatarClient = {\n baseUrl: root,\n\n url: (options) => avatarUrl(root, merge(options)),\n\n srcSet: (options, densities) => avatarSrcSet(root, merge(options), densities),\n\n async fetch(options) {\n const merged = merge(options);\n const response = await doFetch(avatarUrl(root, merged));\n if (!response.ok) return fail(response);\n const bytes = new Uint8Array(await response.arrayBuffer());\n return {\n bytes,\n contentType: response.headers.get(\"content-type\") ?? `image/${merged.format ?? \"webp\"}`,\n info: readInfo(root, response.headers, merged.size ?? DEFAULT_SIZE),\n };\n },\n\n async dataUri(options) {\n const { bytes, contentType } = await client.fetch(options);\n return `data:${contentType};base64,${toBase64(bytes)}`;\n },\n\n async resolve(options) {\n const merged = merge(options);\n const response = await doFetch(avatarUrl(root, merged), { method: \"HEAD\" });\n if (!response.ok) return fail(response);\n return readInfo(root, response.headers, merged.size ?? DEFAULT_SIZE);\n },\n\n async list(collection = defaults.collection) {\n const qs = collection ? `?collection=${encodeURIComponent(collection)}` : \"\";\n const response = await doFetch(`${root}/photos${qs}`);\n if (!response.ok) return fail(response);\n return (await response.json()) as PhotoIndex;\n },\n\n pick(seed, index) {\n return pick(seed, Array.isArray(index) ? index : (index as PhotoIndex).photos);\n },\n };\n\n return client;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2F;;;ACapF,IAAM,mBAAmB;AAEzB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,eAAe;AAmHrB,SAAS,UAAU,MAAsB;AAC9C,MAAI,CAAC,OAAO,SAAS,IAAI,EAAG,QAAO;AACnC,SAAO,KAAK,IAAI,UAAU,KAAK,IAAI,UAAU,KAAK,MAAM,IAAI,CAAC,CAAC;AAChE;AAGA,SAAS,QAAQ,SAA0B;AACzC,QAAM,WAAW,WAAW,kBAAkB,QAAQ,QAAQ,EAAE;AAChE,SAAO,SAAS,KAAK,OAAO,IAAI,UAAU,GAAG,OAAO;AACtD;AAEA,SAAS,aAAa,OAA8B;AAClD,QAAM,MAAM,MAAM,QAAQ,MAAM,EAAE;AAClC,SAAO,+BAA+B,KAAK,GAAG,IAAI,IAAI,YAAY,IAAI;AACxE;AAQO,SAAS,UAAU,SAA6B,UAAyB,CAAC,GAAW;AAC1F,QAAM,OAAO,QAAQ,OAAO;AAC5B,QAAM,OAAO,QAAQ,aAAa,GAAG,IAAI,IAAI,mBAAmB,QAAQ,UAAU,CAAC,KAAK;AAExF,QAAM,QAAQ,IAAI,gBAAgB;AAClC,MAAI,QAAQ,OAAO,UAAa,QAAQ,OAAO,GAAI,OAAM,IAAI,MAAM,QAAQ,EAAE;AAC7E,MAAI,QAAQ,SAAS,UAAa,QAAQ,SAAS,GAAI,OAAM,IAAI,QAAQ,OAAO,QAAQ,IAAI,CAAC;AAC7F,MAAI,QAAQ,SAAS,OAAW,OAAM,IAAI,Q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@@ -0,0 +1,63 @@
1
+ import * as react from 'react';
2
+ import { ImgHTMLAttributes, ReactNode } from 'react';
3
+
4
+ declare const CROPS: readonly ["square", "portrait", "landscape", "phone", "tablet", "ultrawide"];
5
+ type Crop = (typeof CROPS)[number];
6
+ declare const FORMATS: readonly ["webp", "png", "jpeg"];
7
+ type Format = (typeof FORMATS)[number];
8
+ type AvatarOptions = {
9
+ /** Collection to draw from, e.g. `gta-vi`. Omit to use every collection. */
10
+ collection?: string;
11
+ /**
12
+ * Exact image id. Unknown ids are a 404 — unless a `seed` is also given, in
13
+ * which case the API falls back to the seed.
14
+ */
15
+ id?: string;
16
+ /**
17
+ * Anything: an email, username, uuid, number. The same seed always maps to
18
+ * the same image (for a fixed library). Never 404s.
19
+ */
20
+ seed?: string | number;
21
+ /** Pixels, 8–2160. Defaults to 80. Never upscaled past the source image. */
22
+ size?: number;
23
+ /** Which crop of the image to use. Defaults to `square`. */
24
+ crop?: Crop | (string & {});
25
+ /** `full` keeps the original aspect ratio (no mask). Defaults to `cover`. */
26
+ fit?: "cover" | "full";
27
+ /** Square corners instead of the default circle mask. */
28
+ square?: boolean;
29
+ /** Output format. Defaults to `webp`. */
30
+ format?: Format;
31
+ /** Hex corner fill used when a circle is encoded as JPEG, e.g. `#0b0b0f`. */
32
+ background?: string;
33
+ };
34
+
35
+ type ProviderValue = {
36
+ baseUrl?: string;
37
+ defaults?: AvatarOptions;
38
+ };
39
+ /** Set the service URL (defaults to https://veyce.vercel.app) and shared defaults once for every `<Avatar>` below. */
40
+ declare function AvatarProvider({ baseUrl, defaults, children, }: ProviderValue & {
41
+ children?: ReactNode;
42
+ }): react.JSX.Element;
43
+ type AvatarProps = AvatarOptions & Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "srcSet" | "id" | "crossOrigin"> & {
44
+ /** Overrides the provider's `baseUrl`. */
45
+ baseUrl?: string;
46
+ /** Emit a 1x/2x/3x `srcSet`. Defaults to true. */
47
+ hiDpi?: boolean;
48
+ /** The `id` HTML attribute (`id` itself is the image id). */
49
+ htmlId?: string;
50
+ };
51
+ /**
52
+ * `<Avatar seed="ada@example.com" size={48} />`
53
+ *
54
+ * Renders a plain `<img>` with width/height set (no layout shift), lazy loading
55
+ * and a high-density `srcSet`.
56
+ */
57
+ declare function Avatar({ baseUrl, collection, id, seed, size, crop, fit, square, format, background, hiDpi, htmlId, alt, loading, decoding, ...img }: AvatarProps): react.JSX.Element;
58
+ /** Hook form: `const src = useAvatarUrl({ seed: user.email, size: 64 })`. */
59
+ declare function useAvatarUrl(options?: AvatarOptions & {
60
+ baseUrl?: string;
61
+ }): string;
62
+
63
+ export { Avatar, type AvatarOptions, type AvatarProps, AvatarProvider, useAvatarUrl };
@@ -0,0 +1,63 @@
1
+ import * as react from 'react';
2
+ import { ImgHTMLAttributes, ReactNode } from 'react';
3
+
4
+ declare const CROPS: readonly ["square", "portrait", "landscape", "phone", "tablet", "ultrawide"];
5
+ type Crop = (typeof CROPS)[number];
6
+ declare const FORMATS: readonly ["webp", "png", "jpeg"];
7
+ type Format = (typeof FORMATS)[number];
8
+ type AvatarOptions = {
9
+ /** Collection to draw from, e.g. `gta-vi`. Omit to use every collection. */
10
+ collection?: string;
11
+ /**
12
+ * Exact image id. Unknown ids are a 404 — unless a `seed` is also given, in
13
+ * which case the API falls back to the seed.
14
+ */
15
+ id?: string;
16
+ /**
17
+ * Anything: an email, username, uuid, number. The same seed always maps to
18
+ * the same image (for a fixed library). Never 404s.
19
+ */
20
+ seed?: string | number;
21
+ /** Pixels, 8–2160. Defaults to 80. Never upscaled past the source image. */
22
+ size?: number;
23
+ /** Which crop of the image to use. Defaults to `square`. */
24
+ crop?: Crop | (string & {});
25
+ /** `full` keeps the original aspect ratio (no mask). Defaults to `cover`. */
26
+ fit?: "cover" | "full";
27
+ /** Square corners instead of the default circle mask. */
28
+ square?: boolean;
29
+ /** Output format. Defaults to `webp`. */
30
+ format?: Format;
31
+ /** Hex corner fill used when a circle is encoded as JPEG, e.g. `#0b0b0f`. */
32
+ background?: string;
33
+ };
34
+
35
+ type ProviderValue = {
36
+ baseUrl?: string;
37
+ defaults?: AvatarOptions;
38
+ };
39
+ /** Set the service URL (defaults to https://veyce.vercel.app) and shared defaults once for every `<Avatar>` below. */
40
+ declare function AvatarProvider({ baseUrl, defaults, children, }: ProviderValue & {
41
+ children?: ReactNode;
42
+ }): react.JSX.Element;
43
+ type AvatarProps = AvatarOptions & Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "srcSet" | "id" | "crossOrigin"> & {
44
+ /** Overrides the provider's `baseUrl`. */
45
+ baseUrl?: string;
46
+ /** Emit a 1x/2x/3x `srcSet`. Defaults to true. */
47
+ hiDpi?: boolean;
48
+ /** The `id` HTML attribute (`id` itself is the image id). */
49
+ htmlId?: string;
50
+ };
51
+ /**
52
+ * `<Avatar seed="ada@example.com" size={48} />`
53
+ *
54
+ * Renders a plain `<img>` with width/height set (no layout shift), lazy loading
55
+ * and a high-density `srcSet`.
56
+ */
57
+ declare function Avatar({ baseUrl, collection, id, seed, size, crop, fit, square, format, background, hiDpi, htmlId, alt, loading, decoding, ...img }: AvatarProps): react.JSX.Element;
58
+ /** Hook form: `const src = useAvatarUrl({ seed: user.email, size: 64 })`. */
59
+ declare function useAvatarUrl(options?: AvatarOptions & {
60
+ baseUrl?: string;
61
+ }): string;
62
+
63
+ export { Avatar, type AvatarOptions, type AvatarProps, AvatarProvider, useAvatarUrl };
package/dist/react.js ADDED
@@ -0,0 +1,115 @@
1
+ "use client";
2
+
3
+ // src/react.tsx
4
+ import { createContext, useContext, useMemo } from "react";
5
+
6
+ // src/index.ts
7
+ var DEFAULT_BASE_URL = "https://veyce.vercel.app";
8
+ var MIN_SIZE = 8;
9
+ var MAX_SIZE = 2160;
10
+ var DEFAULT_SIZE = 80;
11
+ function clampSize(size) {
12
+ if (!Number.isFinite(size)) return DEFAULT_SIZE;
13
+ return Math.min(MAX_SIZE, Math.max(MIN_SIZE, Math.round(size)));
14
+ }
15
+ function apiRoot(baseUrl) {
16
+ const trimmed = (baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
17
+ return /\/api$/.test(trimmed) ? trimmed : `${trimmed}/api`;
18
+ }
19
+ function normalizeHex(value) {
20
+ const hex = value.replace(/^#/, "");
21
+ return /^([0-9a-f]{3}|[0-9a-f]{6})$/i.test(hex) ? hex.toLowerCase() : null;
22
+ }
23
+ function avatarUrl(baseUrl, options = {}) {
24
+ const root = apiRoot(baseUrl);
25
+ const path = options.collection ? `${root}/${encodeURIComponent(options.collection)}` : root;
26
+ const query = new URLSearchParams();
27
+ if (options.id !== void 0 && options.id !== "") query.set("id", options.id);
28
+ if (options.seed !== void 0 && options.seed !== "") query.set("seed", String(options.seed));
29
+ if (options.size !== void 0) query.set("size", String(clampSize(options.size)));
30
+ if (options.crop) query.set("crop", options.crop);
31
+ if (options.fit && options.fit !== "cover") query.set("fit", options.fit);
32
+ if (options.square) query.set("square", "true");
33
+ if (options.format && options.format !== "webp") query.set("format", options.format);
34
+ if (options.background) {
35
+ const hex = normalizeHex(options.background);
36
+ if (!hex) throw new TypeError(`veyce: invalid background "${options.background}".`);
37
+ query.set("bg", hex);
38
+ }
39
+ const qs = query.toString();
40
+ return qs ? `${path}?${qs}` : path;
41
+ }
42
+ function avatarSrcSet(baseUrl, options = {}, densities = [1, 2, 3]) {
43
+ const size = options.size ?? DEFAULT_SIZE;
44
+ const seen = /* @__PURE__ */ new Set();
45
+ return densities.map((density) => ({ density, px: clampSize(size * density) })).filter(({ px }) => seen.has(px) ? false : (seen.add(px), true)).map(({ density, px }) => `${avatarUrl(baseUrl, { ...options, size: px })} ${density}x`).join(", ");
46
+ }
47
+
48
+ // src/react.tsx
49
+ import { jsx } from "react/jsx-runtime";
50
+ var AvatarContext = createContext(null);
51
+ function AvatarProvider({
52
+ baseUrl,
53
+ defaults,
54
+ children
55
+ }) {
56
+ const value = useMemo(() => ({ baseUrl, defaults }), [baseUrl, defaults]);
57
+ return /* @__PURE__ */ jsx(AvatarContext.Provider, { value, children });
58
+ }
59
+ function Avatar({
60
+ baseUrl,
61
+ collection,
62
+ id,
63
+ seed,
64
+ size,
65
+ crop,
66
+ fit,
67
+ square,
68
+ format,
69
+ background,
70
+ hiDpi = true,
71
+ htmlId,
72
+ alt = "",
73
+ loading = "lazy",
74
+ decoding = "async",
75
+ ...img
76
+ }) {
77
+ const context = useContext(AvatarContext);
78
+ const base = baseUrl ?? context?.baseUrl;
79
+ const own = { collection, id, seed, size, crop, fit, square, format, background };
80
+ for (const key of Object.keys(own)) {
81
+ if (own[key] === void 0) delete own[key];
82
+ }
83
+ const options = { ...context?.defaults, ...own };
84
+ const px = clampSize(options.size ?? DEFAULT_SIZE);
85
+ return (
86
+ // A plain <img> on purpose: the service already resizes and encodes.
87
+ // eslint-disable-next-line @next/next/no-img-element
88
+ /* @__PURE__ */ jsx(
89
+ "img",
90
+ {
91
+ ...img,
92
+ id: htmlId,
93
+ src: avatarUrl(base, { ...options, size: px }),
94
+ srcSet: hiDpi ? avatarSrcSet(base, { ...options, size: px }) : void 0,
95
+ width: img.width ?? px,
96
+ height: img.height ?? px,
97
+ alt,
98
+ loading,
99
+ decoding
100
+ }
101
+ )
102
+ );
103
+ }
104
+ function useAvatarUrl(options = {}) {
105
+ const context = useContext(AvatarContext);
106
+ const { baseUrl, ...rest } = options;
107
+ const base = baseUrl ?? context?.baseUrl;
108
+ return avatarUrl(base, { ...context?.defaults, ...rest });
109
+ }
110
+ export {
111
+ Avatar,
112
+ AvatarProvider,
113
+ useAvatarUrl
114
+ };
115
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/react.tsx","../src/index.ts"],"sourcesContent":["import { createContext, useContext, useMemo, type ImgHTMLAttributes, type ReactNode } from \"react\";\nimport {\n avatarSrcSet,\n avatarUrl,\n clampSize,\n DEFAULT_SIZE,\n type AvatarOptions,\n} from \"./index\";\n\ntype ProviderValue = { baseUrl?: string; defaults?: AvatarOptions };\n\nconst AvatarContext = createContext<ProviderValue | null>(null);\n\n/** Set the service URL (defaults to https://veyce.vercel.app) and shared defaults once for every `<Avatar>` below. */\nexport function AvatarProvider({\n baseUrl,\n defaults,\n children,\n}: ProviderValue & { children?: ReactNode }) {\n const value = useMemo(() => ({ baseUrl, defaults }), [baseUrl, defaults]);\n return <AvatarContext.Provider value={value}>{children}</AvatarContext.Provider>;\n}\n\nexport type AvatarProps = AvatarOptions &\n Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"srcSet\" | \"id\" | \"crossOrigin\"> & {\n /** Overrides the provider's `baseUrl`. */\n baseUrl?: string;\n /** Emit a 1x/2x/3x `srcSet`. Defaults to true. */\n hiDpi?: boolean;\n /** The `id` HTML attribute (`id` itself is the image id). */\n htmlId?: string;\n };\n\n/**\n * `<Avatar seed=\"ada@example.com\" size={48} />`\n *\n * Renders a plain `<img>` with width/height set (no layout shift), lazy loading\n * and a high-density `srcSet`.\n */\nexport function Avatar({\n baseUrl,\n collection,\n id,\n seed,\n size,\n crop,\n fit,\n square,\n format,\n background,\n hiDpi = true,\n htmlId,\n alt = \"\",\n loading = \"lazy\",\n decoding = \"async\",\n ...img\n}: AvatarProps) {\n const context = useContext(AvatarContext);\n const base = baseUrl ?? context?.baseUrl;\n\n const own: AvatarOptions = { collection, id, seed, size, crop, fit, square, format, background };\n for (const key of Object.keys(own) as (keyof AvatarOptions)[]) {\n if (own[key] === undefined) delete own[key];\n }\n const options: AvatarOptions = { ...context?.defaults, ...own };\n const px = clampSize(options.size ?? DEFAULT_SIZE);\n\n return (\n // A plain <img> on purpose: the service already resizes and encodes.\n // eslint-disable-next-line @next/next/no-img-element\n <img\n {...img}\n id={htmlId}\n src={avatarUrl(base, { ...options, size: px })}\n srcSet={hiDpi ? avatarSrcSet(base, { ...options, size: px }) : undefined}\n width={img.width ?? px}\n height={img.height ?? px}\n alt={alt}\n loading={loading}\n decoding={decoding}\n />\n );\n}\n\n/** Hook form: `const src = useAvatarUrl({ seed: user.email, size: 64 })`. */\nexport function useAvatarUrl(options: AvatarOptions & { baseUrl?: string } = {}): string {\n const context = useContext(AvatarContext);\n const { baseUrl, ...rest } = options;\n const base = baseUrl ?? context?.baseUrl;\n return avatarUrl(base, { ...context?.defaults, ...rest });\n}\n\nexport type { AvatarOptions } from \"./index\";\n","/**\n * veyce — a tiny, dependency-free client for the avatars API.\n *\n * const avatars = createAvatars(); // uses https://veyce.vercel.app\n *\n * avatars.url({ seed: \"ada@example.com\", size: 96 }); // any string -> always an avatar\n * avatars.url({ id: \"raul\", collection: \"gta-vi\" }); // exact id -> that image, or 404\n * avatars.url({ id: user.avatarId, seed: user.email }); // exact if it exists, seed otherwise\n *\n * Works in browsers, Node 18+, Deno, Bun and edge runtimes.\n */\n\n/** The public veyce service. Used whenever no `baseUrl` is given. */\nexport const DEFAULT_BASE_URL = \"https://veyce.vercel.app\";\n\nexport const MIN_SIZE = 8;\nexport const MAX_SIZE = 2160;\nexport const DEFAULT_SIZE = 80;\n\nexport const CROPS = [\"square\", \"portrait\", \"landscape\", \"phone\", \"tablet\", \"ultrawide\"] as const;\nexport type Crop = (typeof CROPS)[number];\n\nexport const FORMATS = [\"webp\", \"png\", \"jpeg\"] as const;\nexport type Format = (typeof FORMATS)[number];\n\nexport type AvatarOptions = {\n /** Collection to draw from, e.g. `gta-vi`. Omit to use every collection. */\n collection?: string;\n /**\n * Exact image id. Unknown ids are a 404 — unless a `seed` is also given, in\n * which case the API falls back to the seed.\n */\n id?: string;\n /**\n * Anything: an email, username, uuid, number. The same seed always maps to\n * the same image (for a fixed library). Never 404s.\n */\n seed?: string | number;\n /** Pixels, 8–2160. Defaults to 80. Never upscaled past the source image. */\n size?: number;\n /** Which crop of the image to use. Defaults to `square`. */\n crop?: Crop | (string & {});\n /** `full` keeps the original aspect ratio (no mask). Defaults to `cover`. */\n fit?: \"cover\" | \"full\";\n /** Square corners instead of the default circle mask. */\n square?: boolean;\n /** Output format. Defaults to `webp`. */\n format?: Format;\n /** Hex corner fill used when a circle is encoded as JPEG, e.g. `#0b0b0f`. */\n background?: string;\n};\n\nexport type ClientConfig = {\n /** Where the avatars service is hosted. Defaults to `https://veyce.vercel.app`. A trailing `/api` is fine. */\n baseUrl?: string;\n /** Options applied to every call; per-call options win. */\n defaults?: AvatarOptions;\n /** Custom fetch (for tests, proxies or older runtimes). Defaults to `globalThis.fetch`. */\n fetch?: typeof fetch;\n};\n\n/** How the API chose the image. */\nexport type Match = \"id\" | \"seed\" | \"random\";\n\nexport type AvatarInfo = {\n collection: string;\n id: string;\n crop: string;\n /** The real pixel size served (may be smaller than requested). */\n size: number;\n match: Match;\n /** Stable URL that addresses this exact image by id — store this to \"pin\" a seeded avatar. */\n url: string;\n};\n\nexport type Photo = {\n id: string;\n label: string;\n collection: string;\n crops: string[];\n /** Path on the service, e.g. `/api/gta-vi/raul`. */\n url: string;\n};\n\nexport type PhotoIndex = {\n count: number;\n collections: string[];\n size: { min: number; max: number; default: number };\n photos: Photo[];\n};\n\nexport type AvatarImage = {\n bytes: Uint8Array;\n contentType: string;\n info: AvatarInfo;\n};\n\nexport class AvatarError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body?: unknown) {\n super(message);\n this.name = \"AvatarError\";\n this.status = status;\n this.body = body;\n }\n}\n\n/**\n * The seed hash the service uses. Exposed so you can map seeds to images\n * offline (see `pick`) and get the exact same answer as the API.\n */\nexport function hashSeed(seed: string | number): number {\n const value = String(seed);\n let hash = 0;\n for (let i = 0; i < value.length; i += 1) {\n hash = (hash << 5) - hash + value.charCodeAt(i);\n hash |= 0;\n }\n return Math.abs(hash) || 1;\n}\n\n/**\n * Offline seed -> photo, identical to the API's choice for the same library.\n * Pass `photos` from `list()` (scoped to the same collection you pass the API).\n */\nexport function pick<T>(seed: string | number, photos: readonly T[]): T | undefined {\n if (!photos.length) return undefined;\n return photos[hashSeed(seed) % photos.length];\n}\n\nexport function clampSize(size: number): number {\n if (!Number.isFinite(size)) return DEFAULT_SIZE;\n return Math.min(MAX_SIZE, Math.max(MIN_SIZE, Math.round(size)));\n}\n\n/** `https://x.com/`, `https://x.com/api` -> `https://x.com/api` */\nfunction apiRoot(baseUrl?: string): string {\n const trimmed = (baseUrl || DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n return /\\/api$/.test(trimmed) ? trimmed : `${trimmed}/api`;\n}\n\nfunction normalizeHex(value: string): string | null {\n const hex = value.replace(/^#/, \"\");\n return /^([0-9a-f]{3}|[0-9a-f]{6})$/i.test(hex) ? hex.toLowerCase() : null;\n}\n\n/**\n * Build an avatar URL. Pure string work — no network, safe to call in render.\n *\n * Ids and seeds always go in the query string, so a seed that happens to look\n * like an id, a size or a crop is never misread.\n */\nexport function avatarUrl(baseUrl: string | undefined, options: AvatarOptions = {}): string {\n const root = apiRoot(baseUrl);\n const path = options.collection ? `${root}/${encodeURIComponent(options.collection)}` : root;\n\n const query = new URLSearchParams();\n if (options.id !== undefined && options.id !== \"\") query.set(\"id\", options.id);\n if (options.seed !== undefined && options.seed !== \"\") query.set(\"seed\", String(options.seed));\n if (options.size !== undefined) query.set(\"size\", String(clampSize(options.size)));\n if (options.crop) query.set(\"crop\", options.crop);\n if (options.fit && options.fit !== \"cover\") query.set(\"fit\", options.fit);\n if (options.square) query.set(\"square\", \"true\");\n if (options.format && options.format !== \"webp\") query.set(\"format\", options.format);\n if (options.background) {\n const hex = normalizeHex(options.background);\n if (!hex) throw new TypeError(`veyce: invalid background \"${options.background}\".`);\n query.set(\"bg\", hex);\n }\n\n const qs = query.toString();\n return qs ? `${path}?${qs}` : path;\n}\n\n/** `url 1x, url 2x, url 3x` for crisp avatars on high-density screens. */\nexport function avatarSrcSet(\n baseUrl: string | undefined,\n options: AvatarOptions = {},\n densities: readonly number[] = [1, 2, 3],\n): string {\n const size = options.size ?? DEFAULT_SIZE;\n const seen = new Set<number>();\n return densities\n .map((density) => ({ density, px: clampSize(size * density) }))\n .filter(({ px }) => (seen.has(px) ? false : (seen.add(px), true)))\n .map(({ density, px }) => `${avatarUrl(baseUrl, { ...options, size: px })} ${density}x`)\n .join(\", \");\n}\n\nfunction readInfo(root: string, headers: Headers, requested: number): AvatarInfo {\n const collection = headers.get(\"x-photo-collection\") ?? \"\";\n const id = headers.get(\"x-photo-id\") ?? \"\";\n const match = (headers.get(\"x-photo-match\") as Match | null) ?? \"id\";\n return {\n collection,\n id,\n crop: headers.get(\"x-photo-crop\") ?? \"square\",\n size: Number(headers.get(\"x-photo-size\") ?? requested),\n match,\n url: avatarUrl(root, { collection, id }),\n };\n}\n\nasync function fail(response: Response): Promise<never> {\n let body: unknown;\n let message =\n response.status === 404\n ? \"veyce: no image matches (unknown id or collection) — pass a `seed` to always get one\"\n : response.status === 409\n ? \"veyce: that id exists in several collections — pass `collection`\"\n : `veyce: request failed with ${response.status}`;\n try {\n body = await response.json();\n const error = (body as { error?: unknown })?.error;\n if (typeof error === \"string\") message = `veyce: ${error}`;\n } catch {\n // not JSON — keep the generic message\n }\n throw new AvatarError(message, response.status, body);\n}\n\nfunction toBase64(bytes: Uint8Array): string {\n const B = (globalThis as { Buffer?: { from(b: Uint8Array): { toString(enc: string): string } } })\n .Buffer;\n if (B) return B.from(bytes).toString(\"base64\");\n let binary = \"\";\n for (let i = 0; i < bytes.length; i += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));\n }\n return btoa(binary);\n}\n\nexport type AvatarClient = {\n readonly baseUrl: string;\n /** Avatar URL for an `<img src>`. No network. */\n url(options?: AvatarOptions): string;\n /** `srcset` value with 1x/2x/3x variants. No network. */\n srcSet(options?: AvatarOptions, densities?: readonly number[]): string;\n /** Download the image bytes (plus which image it was). */\n fetch(options?: AvatarOptions): Promise<AvatarImage>;\n /** Download as a `data:` URI — handy for emails, canvases and offline storage. */\n dataUri(options?: AvatarOptions): Promise<string>;\n /** Ask which image a request lands on, without downloading it (HEAD). */\n resolve(options?: AvatarOptions): Promise<AvatarInfo>;\n /** The library index: every collection and id. */\n list(collection?: string): Promise<PhotoIndex>;\n /** Offline seed -> photo, using an index you already fetched with `list()`. */\n pick(seed: string | number, index: PhotoIndex | readonly Photo[]): Photo | undefined;\n};\n\nexport function createAvatars(config: ClientConfig = {}): AvatarClient {\n const root = apiRoot(config.baseUrl);\n const defaults = config.defaults ?? {};\n const doFetch = (input: string, init?: RequestInit) => {\n const f = config.fetch ?? globalThis.fetch;\n if (!f) throw new Error(\"veyce: no global fetch; pass `fetch` in the config.\");\n return f(input, init);\n };\n const merge = (options?: AvatarOptions): AvatarOptions => ({ ...defaults, ...options });\n\n const client: AvatarClient = {\n baseUrl: root,\n\n url: (options) => avatarUrl(root, merge(options)),\n\n srcSet: (options, densities) => avatarSrcSet(root, merge(options), densities),\n\n async fetch(options) {\n const merged = merge(options);\n const response = await doFetch(avatarUrl(root, merged));\n if (!response.ok) return fail(response);\n const bytes = new Uint8Array(await response.arrayBuffer());\n return {\n bytes,\n contentType: response.headers.get(\"content-type\") ?? `image/${merged.format ?? \"webp\"}`,\n info: readInfo(root, response.headers, merged.size ?? DEFAULT_SIZE),\n };\n },\n\n async dataUri(options) {\n const { bytes, contentType } = await client.fetch(options);\n return `data:${contentType};base64,${toBase64(bytes)}`;\n },\n\n async resolve(options) {\n const merged = merge(options);\n const response = await doFetch(avatarUrl(root, merged), { method: \"HEAD\" });\n if (!response.ok) return fail(response);\n return readInfo(root, response.headers, merged.size ?? DEFAULT_SIZE);\n },\n\n async list(collection = defaults.collection) {\n const qs = collection ? `?collection=${encodeURIComponent(collection)}` : \"\";\n const response = await doFetch(`${root}/photos${qs}`);\n if (!response.ok) return fail(response);\n return (await response.json()) as PhotoIndex;\n },\n\n pick(seed, index) {\n return pick(seed, Array.isArray(index) ? index : (index as PhotoIndex).photos);\n },\n };\n\n return client;\n}\n"],"mappings":";;;AAAA,SAAS,eAAe,YAAY,eAAuD;;;ACapF,IAAM,mBAAmB;AAEzB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,eAAe;AAmHrB,SAAS,UAAU,MAAsB;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AK,QAAQ,QAAQ,WAAW;AAC/F,aAAW,OAAO,OAAO,KAAK,GAAG,GAA8B;AAC7D,QAAI,IAAI,GAAG,MAAM,OAAW,QAAO,IAAI,GAAG;AAAA,EAC5C;AACA,QAAM,UAAyB,EAAE,GAAG,SAAS,UAAU,GAAG,IAAI;AAC9D,QAAM,KAAK,UAAU,QAAQ,QAAQ,YAAY;AAEjD;AAAA;AAAA;AAAA,IAGE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,IAAI;AAAA,QACJ,KAAK,UAAU,MAAM,EAAE,GAAG,SAAS,MAAM,GAAG,CAAC;AAAA,QAC7C,QAAQ,QAAQ,aAAa,MAAM,EAAE,GAAG,SAAS,MAAM,GAAG,CAAC,IAAI;AAAA,QAC/D,OAAO,IAAI,SAAS;AAAA,QACpB,QAAQ,IAAI,UAAU;AAAA,QACtB;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF;AAAA;AAEJ;AAGO,SAAS,aAAa,UAAgD,CAAC,GAAW;AACvF,QAAM,UAAU,WAAW,aAAa;AACxC,QAAM,EAAE,SAAS,GAAG,KAAK,IAAI;AAC7B,QAAM,OAAO,WAAW,SAAS;AACjC,SAAO,UAAU,MAAM,EAAE,GAAG,SAAS,UAAU,GAAG,KAAK,CAAC;AAC1D;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,78 @@
1
1
  {
2
2
  "name": "veyce",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Deterministic avatars from your own image library. Exact ids or any seed (email, username, uuid) mapped to the same image every time.",
5
+ "keywords": [
6
+ "avatar",
7
+ "avatars",
8
+ "identicon",
9
+ "seed",
10
+ "profile-picture",
11
+ "deterministic",
12
+ "react"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "Mohamed Salah",
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "import": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/index.d.cts",
29
+ "default": "./dist/index.cjs"
30
+ }
31
+ },
32
+ "./react": {
33
+ "import": {
34
+ "types": "./dist/react.d.ts",
35
+ "default": "./dist/react.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/react.d.cts",
39
+ "default": "./dist/react.cjs"
40
+ }
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "bin": {
45
+ "veyce": "./dist/cli.js"
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "README.md",
50
+ "LICENSE"
51
+ ],
52
+ "engines": {
53
+ "node": ">=18"
54
+ },
55
+ "scripts": {
56
+ "build": "tsup",
57
+ "dev": "tsup --watch",
58
+ "typecheck": "tsc --noEmit",
59
+ "test": "npm run build && node --test test/*.test.mjs",
60
+ "prepublishOnly": "npm run typecheck && npm test"
61
+ },
62
+ "peerDependencies": {
63
+ "react": ">=17"
64
+ },
65
+ "peerDependenciesMeta": {
66
+ "react": {
67
+ "optional": true
68
+ }
69
+ },
70
+ "devDependencies": {
71
+ "@types/node": "^20",
72
+ "@types/react": "^19",
73
+ "react": "19.3.0",
74
+ "react-dom": "19.3.0",
75
+ "tsup": "^8.5.0",
76
+ "typescript": "^5"
77
+ }
78
+ }