TTyko

Пакети / Зображення

@tykonpm/image-core

v0.5.2

Правила пресетів без фреймворка: ширини, srcset, маніфести, кеш описів, безпечна заміна копій.

$ npm i @tykonpm/image-core

Спробуйте наживо

planWidths(2400)[160,320,800,1600]
isSmallOriginal(2400)false
variantPath(src, 160)"/thumbs/160/catalog/portrait.webp"
pickVariant(entry, 400, 2)"/thumbs/800/catalog/portrait.webp"
buildSrcSet(entry)/thumbs/160/catalog/portrait.webp 160w, /thumbs/320/catalog/portrait.webp 320w, /thumbs/800/catalog/portrait.webp 800w, /thumbs/1600/catalog/portrait.webp 1600w, /catalog/portrait.jpg 2400w

← Усі пакети Tyko

Framework-free rules for image presets. No storage dependency, no bundled images.

ts
import { planWidths, pickVariant, buildSrcSet, variantPath } from "@tykonpm/image-core";
planWidths(500);                       // [160, 320, 500] — never upscales
variantPath("/catalog/x.jpg", 320);    // "/thumbs/320/catalog/x.webp"
pickVariant(entry, 400, 2);            // smallest variant ≥ 800px, else original
buildSrcSet(entry);                    // "… 160w, … 800w, /a.jpg 2400w"

ImageStorageAdapter lets you plug any storage (S3, own server, etc.).

Cache and safe regeneration

ts
const loader = createManifestLoader(storage);          // LRU + dedup + missing-TTL
const m = await loader.load(visibleSrcs);
const { entry } = await replaceVariants(storage, src, { url, width }, variants, { previous: m[src] });
loader.set(src, entry);                                // old copies removed only after save

Using in an AI / vibe-coding platform

Features, limitations and adapter recipes: AI-GUIDE.md in this package (node_modules/@tykonpm/image-core/AI-GUIDE.md).