foldkit-media 0.3.0 → 0.3.1
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/vite/index.mjs +15 -4
- package/dist/vite/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/vite/index.mjs
CHANGED
|
@@ -236,10 +236,21 @@ const icons = (options = {}) => {
|
|
|
236
236
|
}
|
|
237
237
|
const icons = [];
|
|
238
238
|
const refused = [];
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
239
|
+
const drawn = (name) => {
|
|
240
|
+
let current = name;
|
|
241
|
+
for (let step = 0; step < 16 && set.aliases !== void 0 && Object.hasOwn(set.aliases, current); step++) current = set.aliases[current].parent;
|
|
242
|
+
return current;
|
|
243
|
+
};
|
|
244
|
+
const exported = /* @__PURE__ */ new Map();
|
|
245
|
+
for (const name of namesOf(set)) {
|
|
246
|
+
const as = exportName(name);
|
|
247
|
+
if (exported.get(as) === drawn(name)) continue;
|
|
248
|
+
exported.set(as, drawn(name));
|
|
249
|
+
try {
|
|
250
|
+
icons.push([name, fromIconify(set, name)]);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
refused.push([name, error instanceof Error ? error.message : String(error)]);
|
|
253
|
+
}
|
|
243
254
|
}
|
|
244
255
|
return {
|
|
245
256
|
icons: named(prefix, icons),
|
package/dist/vite/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Widths.standard"],"sources":["../../src/vite/images.ts","../../src/vite/index.ts"],"sourcesContent":["/**\n * Images as imports: `import hero from './hero.jpg?image'` gives `{ asset,\n * provider }`, ready for `Picture.derive` or `foldkit-mixins-ui`'s `Image.view`.\n * The build reads the file's facts once (`describe`, through sharp), writes a\n * file for each ladder width up to the original's own in each format, and\n * names them by content, so a host may keep them for good. The development\n * server makes the same variants when a page asks for them.\n */\nimport { createHash, randomUUID } from 'node:crypto'\nimport { mkdir, readFile, rename, writeFile } from 'node:fs/promises'\nimport { availableParallelism } from 'node:os'\nimport { join, relative, sep } from 'node:path'\nimport { Cause, Effect, Exit, Layer, ManagedRuntime, Option, Schema, Semaphore } from 'effect'\nimport type { Plugin } from 'vite'\nimport { ImageAsset } from '../asset.js'\nimport type { Format } from '../format.js'\nimport type { Variant } from '../variant.js'\nimport * as Widths from '../widths.js'\nimport { describe, type Inspector } from '../describe.js'\nimport { Transformer } from '../server/services.js'\n\nconst QUERY = 'image'\n// The kept facts' and variants' generation: raised when what `describe` reads or the encoder\n// makes changes, so every build re-reads once, and one that changes neither encodes nothing\n// again. sharp's own version is not in it: a patch release would re-encode every AVIF for\n// nothing anyone sees. r2: an original is read as its EXIF orientation shows it.\nconst CACHE_REVISION = 'r2'\nconst DEV_PREFIX = '/@foldkit-media/image/'\nconst DEV_PATH = /^\\/@foldkit-media\\/image\\/([0-9a-f]{64})\\/w(\\d+)\\.(avif|webp|jpeg|png)$/\n\nexport interface ImagesOptions {\n /** The widths offered, up to each original's own: `Widths.standard` unless given. */\n readonly widths?: Widths.Widths | undefined\n /** Formats offered as `source`s, most preferred first: `['avif']` unless given. */\n readonly sources?: ReadonlyArray<Format> | undefined\n /** The `img`'s own format: `webp` unless given. */\n readonly fallback?: Format | undefined\n /** The encoder's quality, 1 to 100; its own default unless given. */\n readonly quality?: number | undefined\n}\n\ntype Media = ManagedRuntime.ManagedRuntime<Inspector | Transformer, never>\n\n/** The widths a build writes of an original: the ladder's below its own, then its own. */\nconst widthsFor = (ladder: Widths.Widths, width: number): ReadonlyArray<number> => [\n ...ladder.values.filter(value => value < width),\n width,\n]\n\n/**\n * Keeps `bytes` at `file` whole or not at all: written beside it, then moved in, so a build\n * stopped halfway leaves no cut-short file that a later build would trust.\n */\nconst keep = async (file: string, bytes: Uint8Array | string) => {\n const partial = `${file}.${randomUUID()}.partial`\n await writeFile(partial, bytes)\n await rename(partial, file)\n}\n\nconst run = async <A, E>(\n media: Media,\n effect: Effect.Effect<A, E, Inspector | Transformer>,\n what: string,\n) => {\n const exit = await media.runPromiseExit(effect)\n if (Exit.isSuccess(exit)) return exit.value\n throw new Error(`foldkit-media/vite: ${what}: ${Cause.pretty(exit.cause)}`)\n}\n\n/**\n * The plugin: an import with `?image` becomes the image's facts and a\n * provider over its variants. sharp is read on the first such import, so an\n * application that imports none needs no sharp.\n */\nexport const images = (options: ImagesOptions = {}): Plugin => {\n const ladder = options.widths ?? Widths.standard\n const sources = options.sources ?? ['avif']\n const fallback = options.fallback ?? 'webp'\n const formats = [...new Set([...sources, fallback])]\n const quality = Option.fromNullishOr(options.quality)\n if (\n Option.isSome(quality) &&\n !(Number.isInteger(quality.value) && quality.value >= 1 && quality.value <= 100)\n ) {\n throw new Error(\n `foldkit-media/vite: a quality is a whole number from 1 to 100, not ${quality.value}.`,\n )\n }\n\n let root = process.cwd()\n let cache = join(root, 'node_modules', '.vite', 'foldkit-media', CACHE_REVISION)\n let serving = false\n /** The originals the development server has been asked to vary, by content hash. */\n const originals = new Map<\n string,\n { readonly bytes: Uint8Array<ArrayBuffer>; readonly widths: ReadonlyArray<number> }\n >()\n\n // Each read decodes a whole original, and a build loads every import at once: as many at a\n // time as there are cores, as the Transformer's own bound.\n const inspecting = Semaphore.makeUnsafe(availableParallelism())\n let media: Promise<Media> | undefined\n const mediaOf = () =>\n (media ??= import('../sharp/index.js').then(\n ({ inspectorSharp, transformerSharp }) =>\n ManagedRuntime.make(Layer.mergeAll(inspectorSharp(), transformerSharp())),\n cause => {\n throw new Error(\n `foldkit-media/vite: a ?image import needs sharp; add it to the application. (${String(cause)})`,\n )\n },\n ))\n\n const factsOf = async (\n key: string,\n bytes: Uint8Array<ArrayBuffer>,\n hash: string,\n ): Promise<ImageAsset> => {\n const file = join(cache, hash, 'asset.json')\n try {\n return Schema.decodeUnknownSync(ImageAsset)({\n ...JSON.parse(await readFile(file, 'utf8')),\n key,\n })\n } catch {\n // Not kept yet, or kept by an older version: the facts are made again, as a cache's are.\n const asset = await run(\n await mediaOf(),\n Semaphore.withPermit(inspecting)(describe(key, bytes)),\n `${key} could not be read`,\n )\n await mkdir(join(cache, hash), { recursive: true })\n await keep(file, JSON.stringify(Schema.encodeSync(ImageAsset)(asset)))\n return asset\n }\n }\n\n const variantOf = async (\n key: string,\n bytes: Uint8Array<ArrayBuffer>,\n hash: string,\n width: number,\n format: Format,\n ): Promise<Uint8Array<ArrayBuffer>> => {\n const name = `w${width}${Option.match(quality, { onNone: () => '', onSome: q => `q${q}` })}.${format}`\n const file = join(cache, hash, name)\n try {\n return new Uint8Array(await readFile(file))\n } catch {\n // Not kept yet: made, and kept for the next build.\n const variant: Variant = { width, format, quality }\n const made = await run(\n await mediaOf(),\n Transformer.use(transformer =>\n transformer.transform(\n { body: new Blob([bytes]).stream(), size: bytes.byteLength },\n variant,\n ),\n ),\n `${key} could not be made ${width} wide in ${format}`,\n )\n await mkdir(join(cache, hash), { recursive: true })\n await keep(file, made.bytes)\n return made.bytes\n }\n }\n\n return {\n name: 'foldkit-media:images',\n // Before Vite's own asset handling, which takes a `.jpg` import of any query as a URL.\n enforce: 'pre',\n configResolved(config) {\n root = config.root\n cache = join(config.cacheDir, 'foldkit-media', CACHE_REVISION)\n serving = config.command === 'serve'\n },\n async load(id) {\n const [file, query] = id.split('?')\n if (query === undefined || !new URLSearchParams(query).has(QUERY)) return undefined\n const bytes = new Uint8Array(await readFile(file!))\n const hash = createHash('sha256').update(bytes).digest('hex')\n const key = relative(root, file!).split(sep).join('/')\n const asset = await factsOf(key, bytes, hash)\n const widths = widthsFor(ladder, asset.width)\n if (serving) originals.set(hash, { bytes, widths })\n const stem = key\n .split('/')\n .pop()!\n .replace(/\\.[^.]+$/, '')\n // Made together: the Transformer bounds how many run at once, and AVIF is slow one by one.\n const files = await Promise.all(\n widths.flatMap(width =>\n formats.map(async format => {\n let url: string\n if (serving) {\n url = JSON.stringify(`${DEV_PREFIX}${hash}/w${width}.${format}`)\n } else {\n const source = await variantOf(key, bytes, hash, width, format)\n const contentHash = createHash('sha256').update(source).digest('hex')\n url = `import.meta.ROLLUP_FILE_URL_${this.emitFile({\n type: 'asset',\n fileName: `${stem}-${width}-${contentHash}.${format}`,\n source,\n })}`\n }\n return `{ width: ${width}, format: ${JSON.stringify(format)}, url: ${url} }`\n }),\n ),\n )\n return [\n `import { Schema } from 'effect'`,\n `import { HashedAsset, Provider } from 'foldkit-media'`,\n `export default {`,\n ` asset: Schema.decodeUnknownSync(HashedAsset)(${JSON.stringify(Schema.encodeSync(ImageAsset)(asset))}),`,\n ` provider: Provider.fromFiles([${files.join(', ')}], ${JSON.stringify({ sources, fallback })}),`,\n `}`,\n ].join('\\n')\n },\n configureServer(server) {\n server.middlewares.use((request, response, next) => {\n const match = DEV_PATH.exec(request.url?.split('?')[0] ?? '')\n if (match === null) return next()\n const [, hash, width, asked] = match\n const original = originals.get(hash!)\n const format = formats.find(offered => offered === asked)\n if (\n original === undefined ||\n format === undefined ||\n !original.widths.includes(Number(width))\n ) {\n response.statusCode = 404\n return response.end()\n }\n variantOf(hash!, original.bytes, hash!, Number(width), format).then(bytes => {\n response.setHeader('Content-Type', `image/${format}`)\n response.setHeader('Cache-Control', 'no-store')\n response.end(bytes)\n }, next)\n })\n },\n }\n}\n","/**\n * Icons as imports: `import { arrowLeft } from 'virtual:foldkit-icons/lucide'`\n * gives the icon's `IconData`, read from an Iconify set or a folder of the\n * application's own SVG files when the build reads the import. The import is\n * the selection, and the bundler drops what nothing imports. A declaration\n * file names every icon of every set, so a misspelt name is a type error.\n */\nimport { readdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { extname, isAbsolute, join, relative, resolve } from 'node:path'\nimport { Schema } from 'effect'\nimport type { Plugin } from 'vite'\nimport type { IconData } from '../icon.js'\nimport { fromIconify, IconifySet, namesOf, parse } from '../icons/index.js'\n\nconst PREFIX = 'virtual:foldkit-icons/'\n// Rollup's mark for a module no file holds, which other plugins leave alone.\nconst RESOLVED = `${String.fromCharCode(0)}${PREFIX}`\nconst SET_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/\n\nexport interface IconsOptions {\n /** Iconify sets by prefix (`lucide`, `uil`), each read from the application's `@iconify-json/<prefix>`. */\n readonly iconify?: ReadonlyArray<string> | undefined\n /** The application's own sets: a name, and a folder whose SVG files are its icons, each named by its file. */\n readonly folders?: Readonly<Record<string, string>> | undefined\n /** Where the declaration of every set is written, from the root: `foldkit-icons.d.ts` unless given; `false` writes none. */\n readonly dts?: string | false | undefined\n}\n\n/** An icon set ready to be a module: each icon under the name it is imported by. */\ninterface ReadSet {\n readonly icons: ReadonlyArray<readonly [exported: string, icon: IconData]>\n /** The icons of an Iconify set the parser refused, and why: left out, so importing one fails. */\n readonly refused: ReadonlyArray<readonly [name: string, reason: string]>\n}\n\n/** `arrow-left` is `arrowLeft`, and `1-circle` `_1Circle`; JavaScript's reserved words export as they are. */\nexport const exportName = (name: string): string => {\n const camel = name.replace(/[-_:.]+([a-zA-Z0-9])/g, (_, next: string) => next.toUpperCase())\n return /^[0-9]/.test(camel) ? `_${camel}` : camel\n}\n\nconst named = (\n set: string,\n entries: ReadonlyArray<readonly [name: string, icon: IconData]>,\n): ReadSet['icons'] => {\n const seen = new Map<string, string>()\n return entries.map(([name, icon]) => {\n const exported = exportName(name)\n if (!/^[A-Za-z_$][\\w$]*$/.test(exported)) {\n throw new Error(`foldkit-media/vite: the icon \"${set}:${name}\" has no name to import it by.`)\n }\n const earlier = seen.get(exported)\n if (earlier !== undefined) {\n throw new Error(\n `foldkit-media/vite: the icons \"${set}:${earlier}\" and \"${set}:${name}\" would both be imported as ${exported}.`,\n )\n }\n seen.set(exported, name)\n return [exported, icon] as const\n })\n}\n\nconst moduleOf = ({ icons }: ReadSet): string =>\n [\n ...icons.map(([, icon], at) => `const i${at} = ${JSON.stringify(icon)}`),\n `export { ${icons.map(([exported], at) => `i${at} as ${exported}`).join(', ')} }`,\n ].join('\\n')\n\nconst declarationOf = (sets: ReadonlyMap<string, ReadSet>): string =>\n [\n '// Written by foldkit-media/vite from the icon sets it is given. Do not edit.',\n ...[...sets].map(([name, { icons, refused }]) =>\n [\n `declare module '${PREFIX}${name}' {`,\n \" import type { IconData } from 'foldkit-media'\",\n ...refused.map(\n ([icon, reason]) => ` // Left out, ${icon}: ${reason.replace(/\\s+/g, ' ')}`,\n ),\n ...icons.map((_, at) => ` const i${at}: IconData`),\n ` export { ${icons.map(([exported], at) => `i${at} as ${exported}`).join(', ')} }`,\n '}',\n ].join('\\n'),\n ),\n '',\n ].join('\\n')\n\n/**\n * The plugin: give it the sets the application imports from. An SVG in a\n * folder that the parser refuses fails the build, naming the file; an icon of\n * an Iconify set that it refuses is left out of the set, and its declaration\n * says why, so only importing that icon fails.\n */\nexport const icons = (options: IconsOptions = {}): Plugin => {\n const iconify = options.iconify ?? []\n const folders = Object.entries(options.folders ?? {})\n for (const name of [...iconify, ...folders.map(([name]) => name)]) {\n if (!SET_NAME.test(name)) {\n throw new Error(\n `foldkit-media/vite: \"${name}\" is not a set name (lowercase words and hyphens).`,\n )\n }\n }\n const twice = [...iconify, ...folders.map(([name]) => name)].find(\n (name, at, all) => all.indexOf(name) !== at,\n )\n if (twice !== undefined) throw new Error(`foldkit-media/vite: the set \"${twice}\" is given twice.`)\n\n let root = process.cwd()\n const read = new Map<string, ReadSet>()\n const folderDirs = new Map(folders)\n const folderOf = (name: string) => resolve(root, folderDirs.get(name)!)\n\n const readIconify = (prefix: string): ReadSet => {\n const require = createRequire(join(root, 'package.json'))\n let file: string\n try {\n file = require.resolve(`@iconify-json/${prefix}/icons.json`)\n } catch {\n throw new Error(\n `foldkit-media/vite: the Iconify set \"${prefix}\" is not installed: add @iconify-json/${prefix}.`,\n )\n }\n let set: IconifySet\n try {\n set = Schema.decodeUnknownSync(IconifySet)(JSON.parse(readFileSync(file, 'utf8')))\n } catch (error) {\n throw new Error(\n `foldkit-media/vite: ${file} is not an Iconify set: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n const icons: Array<readonly [string, IconData]> = []\n const refused: Array<readonly [string, string]> = []\n for (const name of namesOf(set)) {\n try {\n icons.push([name, fromIconify(set, name)])\n } catch (error) {\n refused.push([name, error instanceof Error ? error.message : String(error)])\n }\n }\n return { icons: named(prefix, icons), refused }\n }\n\n const readFolder = (name: string): ReadSet => {\n const folder = folderOf(name)\n const files = readdirSync(folder)\n .filter(file => extname(file) === '.svg')\n .sort()\n return {\n icons: named(\n name,\n files.map(file => {\n const path = join(folder, file)\n return [\n file.slice(0, -4),\n parse(readFileSync(path, 'utf8'), relative(root, path)),\n ] as const\n }),\n ),\n refused: [],\n }\n }\n\n const setOf = (name: string): ReadSet => {\n const known = read.get(name)\n if (known !== undefined) return known\n const made = iconify.includes(name) ? readIconify(name) : readFolder(name)\n read.set(name, made)\n return made\n }\n\n const all = () => [...iconify, ...folders.map(([name]) => name)]\n\n const writeDeclaration = () => {\n if (options.dts === false) return\n const path = resolve(root, options.dts ?? 'foldkit-icons.d.ts')\n const text = declarationOf(new Map(all().map(name => [name, setOf(name)])))\n let current: string | undefined\n try {\n current = readFileSync(path, 'utf8')\n } catch {\n current = undefined\n }\n // Written only when it changes, so a watcher on the file does not see a write of every build.\n if (current !== text) writeFileSync(path, text)\n }\n\n return {\n name: 'foldkit-media:icons',\n configResolved(config) {\n root = config.root\n },\n buildStart() {\n read.clear()\n writeDeclaration()\n for (const [name] of folders) this.addWatchFile(folderOf(name))\n },\n resolveId(id) {\n if (!id.startsWith(PREFIX)) return undefined\n const name = id.slice(PREFIX.length)\n if (!all().includes(name)) {\n throw new Error(\n `foldkit-media/vite: there is no icon set \"${name}\"; the sets given are ${all().join(', ') || 'none'}.`,\n )\n }\n return `${RESOLVED}${name}`\n },\n load(id) {\n if (!id.startsWith(RESOLVED)) return undefined\n const name = id.slice(RESOLVED.length)\n if (folders.some(([folder]) => folder === name)) {\n for (const file of readdirSync(folderOf(name)))\n this.addWatchFile(join(folderOf(name), file))\n }\n return moduleOf(setOf(name))\n },\n configureServer(server) {\n const dirs = folders.map(([name]) => [name, folderOf(name)] as const)\n server.watcher.add(dirs.map(([, dir]) => dir))\n server.watcher.on('all', (_, file) => {\n const changed = dirs.find(([, dir]) => {\n const path = relative(dir, file)\n return !isAbsolute(path) && !path.startsWith('..')\n })\n if (changed === undefined || extname(file) !== '.svg') return\n read.delete(changed[0])\n try {\n writeDeclaration()\n } catch (error) {\n // A throw here would end the server; the set's next load fails with it, where the page shows it.\n server.config.logger.error(error instanceof Error ? error.message : String(error))\n }\n for (const environment of Object.values(server.environments)) {\n const module = environment.moduleGraph.getModuleById(`${RESOLVED}${changed[0]}`)\n if (module !== undefined) environment.moduleGraph.invalidateModule(module)\n }\n server.ws.send({ type: 'full-reload' })\n })\n },\n }\n}\n\nexport { images, type ImagesOptions } from './images.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,QAAQ;AAKd,MAAM,iBAAiB;AACvB,MAAM,aAAa;AACnB,MAAM,WAAW;;AAgBjB,MAAM,aAAa,QAAuB,UAAyC,CACjF,GAAG,OAAO,OAAO,QAAO,UAAS,QAAQ,KAAK,GAC9C,KACF;;;;;AAMA,MAAM,OAAO,OAAO,MAAc,UAA+B;CAC/D,MAAM,UAAU,GAAG,KAAK,GAAG,WAAW,EAAE;CACxC,MAAM,UAAU,SAAS,KAAK;CAC9B,MAAM,OAAO,SAAS,IAAI;AAC5B;AAEA,MAAM,MAAM,OACV,OACA,QACA,SACG;CACH,MAAM,OAAO,MAAM,MAAM,eAAe,MAAM;CAC9C,IAAI,KAAK,UAAU,IAAI,GAAG,OAAO,KAAK;CACtC,MAAM,IAAI,MAAM,uBAAuB,KAAK,IAAI,MAAM,OAAO,KAAK,KAAK,GAAG;AAC5E;;;;;;AAOA,MAAa,UAAU,UAAyB,CAAC,MAAc;CAC7D,MAAM,SAAS,QAAQ,UAAUA;CACjC,MAAM,UAAU,QAAQ,WAAW,CAAC,MAAM;CAC1C,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,UAAU,CA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AW,IAAI,GAC5C,KAAK,MAAM,QAAQ,YAAY,SAAS,IAAI,CAAC,GAC3C,KAAK,aAAa,KAAK,SAAS,IAAI,GAAG,IAAI,CAAC;GAEhD,OAAO,SAAS,MAAM,IAAI,CAAC;EAC7B;EACA,gBAAgB,QAAQ;GACtB,MAAM,OAAO,QAAQ,KAAK,CAAC,UAAU,CAAC,MAAM,SAAS,IAAI,CAAC,CAAU;GACpE,OAAO,QAAQ,IAAI,KAAK,KAAK,GAAG,SAAS,GAAG,CAAC;GAC7C,OAAO,QAAQ,GAAG,QAAQ,GAAG,SAAS;IACpC,MAAM,UAAU,KAAK,MAAM,GAAG,SAAS;KACrC,MAAM,OAAO,SAAS,KAAK,IAAI;KAC/B,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC,KAAK,WAAW,IAAI;IACnD,CAAC;IACD,IAAI,YAAY,KAAA,KAAa,QAAQ,IAAI,MAAM,QAAQ;IACvD,KAAK,OAAO,QAAQ,EAAE;IACtB,IAAI;KACF,iBAAiB;IACnB,SAAS,OAAO;KAEd,OAAO,OAAO,OAAO,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;IACnF;IACA,KAAK,MAAM,eAAe,OAAO,OAAO,OAAO,YAAY,GAAG;KAC5D,MAAM,SAAS,YAAY,YAAY,cAAc,GAAG,WAAW,QAAQ,IAAI;KAC/E,IAAI,WAAW,KAAA,GAAW,YAAY,YAAY,iBAAiB,MAAM;IAC3E;IACA,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;GACxC,CAAC;EACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["Widths.standard"],"sources":["../../src/vite/images.ts","../../src/vite/index.ts"],"sourcesContent":["/**\n * Images as imports: `import hero from './hero.jpg?image'` gives `{ asset,\n * provider }`, ready for `Picture.derive` or `foldkit-mixins-ui`'s `Image.view`.\n * The build reads the file's facts once (`describe`, through sharp), writes a\n * file for each ladder width up to the original's own in each format, and\n * names them by content, so a host may keep them for good. The development\n * server makes the same variants when a page asks for them.\n */\nimport { createHash, randomUUID } from 'node:crypto'\nimport { mkdir, readFile, rename, writeFile } from 'node:fs/promises'\nimport { availableParallelism } from 'node:os'\nimport { join, relative, sep } from 'node:path'\nimport { Cause, Effect, Exit, Layer, ManagedRuntime, Option, Schema, Semaphore } from 'effect'\nimport type { Plugin } from 'vite'\nimport { ImageAsset } from '../asset.js'\nimport type { Format } from '../format.js'\nimport type { Variant } from '../variant.js'\nimport * as Widths from '../widths.js'\nimport { describe, type Inspector } from '../describe.js'\nimport { Transformer } from '../server/services.js'\n\nconst QUERY = 'image'\n// The kept facts' and variants' generation: raised when what `describe` reads or the encoder\n// makes changes, so every build re-reads once, and one that changes neither encodes nothing\n// again. sharp's own version is not in it: a patch release would re-encode every AVIF for\n// nothing anyone sees. r2: an original is read as its EXIF orientation shows it.\nconst CACHE_REVISION = 'r2'\nconst DEV_PREFIX = '/@foldkit-media/image/'\nconst DEV_PATH = /^\\/@foldkit-media\\/image\\/([0-9a-f]{64})\\/w(\\d+)\\.(avif|webp|jpeg|png)$/\n\nexport interface ImagesOptions {\n /** The widths offered, up to each original's own: `Widths.standard` unless given. */\n readonly widths?: Widths.Widths | undefined\n /** Formats offered as `source`s, most preferred first: `['avif']` unless given. */\n readonly sources?: ReadonlyArray<Format> | undefined\n /** The `img`'s own format: `webp` unless given. */\n readonly fallback?: Format | undefined\n /** The encoder's quality, 1 to 100; its own default unless given. */\n readonly quality?: number | undefined\n}\n\ntype Media = ManagedRuntime.ManagedRuntime<Inspector | Transformer, never>\n\n/** The widths a build writes of an original: the ladder's below its own, then its own. */\nconst widthsFor = (ladder: Widths.Widths, width: number): ReadonlyArray<number> => [\n ...ladder.values.filter(value => value < width),\n width,\n]\n\n/**\n * Keeps `bytes` at `file` whole or not at all: written beside it, then moved in, so a build\n * stopped halfway leaves no cut-short file that a later build would trust.\n */\nconst keep = async (file: string, bytes: Uint8Array | string) => {\n const partial = `${file}.${randomUUID()}.partial`\n await writeFile(partial, bytes)\n await rename(partial, file)\n}\n\nconst run = async <A, E>(\n media: Media,\n effect: Effect.Effect<A, E, Inspector | Transformer>,\n what: string,\n) => {\n const exit = await media.runPromiseExit(effect)\n if (Exit.isSuccess(exit)) return exit.value\n throw new Error(`foldkit-media/vite: ${what}: ${Cause.pretty(exit.cause)}`)\n}\n\n/**\n * The plugin: an import with `?image` becomes the image's facts and a\n * provider over its variants. sharp is read on the first such import, so an\n * application that imports none needs no sharp.\n */\nexport const images = (options: ImagesOptions = {}): Plugin => {\n const ladder = options.widths ?? Widths.standard\n const sources = options.sources ?? ['avif']\n const fallback = options.fallback ?? 'webp'\n const formats = [...new Set([...sources, fallback])]\n const quality = Option.fromNullishOr(options.quality)\n if (\n Option.isSome(quality) &&\n !(Number.isInteger(quality.value) && quality.value >= 1 && quality.value <= 100)\n ) {\n throw new Error(\n `foldkit-media/vite: a quality is a whole number from 1 to 100, not ${quality.value}.`,\n )\n }\n\n let root = process.cwd()\n let cache = join(root, 'node_modules', '.vite', 'foldkit-media', CACHE_REVISION)\n let serving = false\n /** The originals the development server has been asked to vary, by content hash. */\n const originals = new Map<\n string,\n { readonly bytes: Uint8Array<ArrayBuffer>; readonly widths: ReadonlyArray<number> }\n >()\n\n // Each read decodes a whole original, and a build loads every import at once: as many at a\n // time as there are cores, as the Transformer's own bound.\n const inspecting = Semaphore.makeUnsafe(availableParallelism())\n let media: Promise<Media> | undefined\n const mediaOf = () =>\n (media ??= import('../sharp/index.js').then(\n ({ inspectorSharp, transformerSharp }) =>\n ManagedRuntime.make(Layer.mergeAll(inspectorSharp(), transformerSharp())),\n cause => {\n throw new Error(\n `foldkit-media/vite: a ?image import needs sharp; add it to the application. (${String(cause)})`,\n )\n },\n ))\n\n const factsOf = async (\n key: string,\n bytes: Uint8Array<ArrayBuffer>,\n hash: string,\n ): Promise<ImageAsset> => {\n const file = join(cache, hash, 'asset.json')\n try {\n return Schema.decodeUnknownSync(ImageAsset)({\n ...JSON.parse(await readFile(file, 'utf8')),\n key,\n })\n } catch {\n // Not kept yet, or kept by an older version: the facts are made again, as a cache's are.\n const asset = await run(\n await mediaOf(),\n Semaphore.withPermit(inspecting)(describe(key, bytes)),\n `${key} could not be read`,\n )\n await mkdir(join(cache, hash), { recursive: true })\n await keep(file, JSON.stringify(Schema.encodeSync(ImageAsset)(asset)))\n return asset\n }\n }\n\n const variantOf = async (\n key: string,\n bytes: Uint8Array<ArrayBuffer>,\n hash: string,\n width: number,\n format: Format,\n ): Promise<Uint8Array<ArrayBuffer>> => {\n const name = `w${width}${Option.match(quality, { onNone: () => '', onSome: q => `q${q}` })}.${format}`\n const file = join(cache, hash, name)\n try {\n return new Uint8Array(await readFile(file))\n } catch {\n // Not kept yet: made, and kept for the next build.\n const variant: Variant = { width, format, quality }\n const made = await run(\n await mediaOf(),\n Transformer.use(transformer =>\n transformer.transform(\n { body: new Blob([bytes]).stream(), size: bytes.byteLength },\n variant,\n ),\n ),\n `${key} could not be made ${width} wide in ${format}`,\n )\n await mkdir(join(cache, hash), { recursive: true })\n await keep(file, made.bytes)\n return made.bytes\n }\n }\n\n return {\n name: 'foldkit-media:images',\n // Before Vite's own asset handling, which takes a `.jpg` import of any query as a URL.\n enforce: 'pre',\n configResolved(config) {\n root = config.root\n cache = join(config.cacheDir, 'foldkit-media', CACHE_REVISION)\n serving = config.command === 'serve'\n },\n async load(id) {\n const [file, query] = id.split('?')\n if (query === undefined || !new URLSearchParams(query).has(QUERY)) return undefined\n const bytes = new Uint8Array(await readFile(file!))\n const hash = createHash('sha256').update(bytes).digest('hex')\n const key = relative(root, file!).split(sep).join('/')\n const asset = await factsOf(key, bytes, hash)\n const widths = widthsFor(ladder, asset.width)\n if (serving) originals.set(hash, { bytes, widths })\n const stem = key\n .split('/')\n .pop()!\n .replace(/\\.[^.]+$/, '')\n // Made together: the Transformer bounds how many run at once, and AVIF is slow one by one.\n const files = await Promise.all(\n widths.flatMap(width =>\n formats.map(async format => {\n let url: string\n if (serving) {\n url = JSON.stringify(`${DEV_PREFIX}${hash}/w${width}.${format}`)\n } else {\n const source = await variantOf(key, bytes, hash, width, format)\n const contentHash = createHash('sha256').update(source).digest('hex')\n url = `import.meta.ROLLUP_FILE_URL_${this.emitFile({\n type: 'asset',\n fileName: `${stem}-${width}-${contentHash}.${format}`,\n source,\n })}`\n }\n return `{ width: ${width}, format: ${JSON.stringify(format)}, url: ${url} }`\n }),\n ),\n )\n return [\n `import { Schema } from 'effect'`,\n `import { HashedAsset, Provider } from 'foldkit-media'`,\n `export default {`,\n ` asset: Schema.decodeUnknownSync(HashedAsset)(${JSON.stringify(Schema.encodeSync(ImageAsset)(asset))}),`,\n ` provider: Provider.fromFiles([${files.join(', ')}], ${JSON.stringify({ sources, fallback })}),`,\n `}`,\n ].join('\\n')\n },\n configureServer(server) {\n server.middlewares.use((request, response, next) => {\n const match = DEV_PATH.exec(request.url?.split('?')[0] ?? '')\n if (match === null) return next()\n const [, hash, width, asked] = match\n const original = originals.get(hash!)\n const format = formats.find(offered => offered === asked)\n if (\n original === undefined ||\n format === undefined ||\n !original.widths.includes(Number(width))\n ) {\n response.statusCode = 404\n return response.end()\n }\n variantOf(hash!, original.bytes, hash!, Number(width), format).then(bytes => {\n response.setHeader('Content-Type', `image/${format}`)\n response.setHeader('Cache-Control', 'no-store')\n response.end(bytes)\n }, next)\n })\n },\n }\n}\n","/**\n * Icons as imports: `import { arrowLeft } from 'virtual:foldkit-icons/lucide'`\n * gives the icon's `IconData`, read from an Iconify set or a folder of the\n * application's own SVG files when the build reads the import. The import is\n * the selection, and the bundler drops what nothing imports. A declaration\n * file names every icon of every set, so a misspelt name is a type error.\n */\nimport { readdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { extname, isAbsolute, join, relative, resolve } from 'node:path'\nimport { Schema } from 'effect'\nimport type { Plugin } from 'vite'\nimport type { IconData } from '../icon.js'\nimport { fromIconify, IconifySet, namesOf, parse } from '../icons/index.js'\n\nconst PREFIX = 'virtual:foldkit-icons/'\n// Rollup's mark for a module no file holds, which other plugins leave alone.\nconst RESOLVED = `${String.fromCharCode(0)}${PREFIX}`\nconst SET_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/\n\nexport interface IconsOptions {\n /** Iconify sets by prefix (`lucide`, `uil`), each read from the application's `@iconify-json/<prefix>`. */\n readonly iconify?: ReadonlyArray<string> | undefined\n /** The application's own sets: a name, and a folder whose SVG files are its icons, each named by its file. */\n readonly folders?: Readonly<Record<string, string>> | undefined\n /** Where the declaration of every set is written, from the root: `foldkit-icons.d.ts` unless given; `false` writes none. */\n readonly dts?: string | false | undefined\n}\n\n/** An icon set ready to be a module: each icon under the name it is imported by. */\ninterface ReadSet {\n readonly icons: ReadonlyArray<readonly [exported: string, icon: IconData]>\n /** The icons of an Iconify set the parser refused, and why: left out, so importing one fails. */\n readonly refused: ReadonlyArray<readonly [name: string, reason: string]>\n}\n\n/** `arrow-left` is `arrowLeft`, and `1-circle` `_1Circle`; JavaScript's reserved words export as they are. */\nexport const exportName = (name: string): string => {\n const camel = name.replace(/[-_:.]+([a-zA-Z0-9])/g, (_, next: string) => next.toUpperCase())\n return /^[0-9]/.test(camel) ? `_${camel}` : camel\n}\n\nconst named = (\n set: string,\n entries: ReadonlyArray<readonly [name: string, icon: IconData]>,\n): ReadSet['icons'] => {\n const seen = new Map<string, string>()\n return entries.map(([name, icon]) => {\n const exported = exportName(name)\n if (!/^[A-Za-z_$][\\w$]*$/.test(exported)) {\n throw new Error(`foldkit-media/vite: the icon \"${set}:${name}\" has no name to import it by.`)\n }\n const earlier = seen.get(exported)\n if (earlier !== undefined) {\n throw new Error(\n `foldkit-media/vite: the icons \"${set}:${earlier}\" and \"${set}:${name}\" would both be imported as ${exported}.`,\n )\n }\n seen.set(exported, name)\n return [exported, icon] as const\n })\n}\n\nconst moduleOf = ({ icons }: ReadSet): string =>\n [\n ...icons.map(([, icon], at) => `const i${at} = ${JSON.stringify(icon)}`),\n `export { ${icons.map(([exported], at) => `i${at} as ${exported}`).join(', ')} }`,\n ].join('\\n')\n\nconst declarationOf = (sets: ReadonlyMap<string, ReadSet>): string =>\n [\n '// Written by foldkit-media/vite from the icon sets it is given. Do not edit.',\n ...[...sets].map(([name, { icons, refused }]) =>\n [\n `declare module '${PREFIX}${name}' {`,\n \" import type { IconData } from 'foldkit-media'\",\n ...refused.map(\n ([icon, reason]) => ` // Left out, ${icon}: ${reason.replace(/\\s+/g, ' ')}`,\n ),\n ...icons.map((_, at) => ` const i${at}: IconData`),\n ` export { ${icons.map(([exported], at) => `i${at} as ${exported}`).join(', ')} }`,\n '}',\n ].join('\\n'),\n ),\n '',\n ].join('\\n')\n\n/**\n * The plugin: give it the sets the application imports from. An SVG in a\n * folder that the parser refuses fails the build, naming the file; an icon of\n * an Iconify set that it refuses is left out of the set, and its declaration\n * says why, so only importing that icon fails.\n */\nexport const icons = (options: IconsOptions = {}): Plugin => {\n const iconify = options.iconify ?? []\n const folders = Object.entries(options.folders ?? {})\n for (const name of [...iconify, ...folders.map(([name]) => name)]) {\n if (!SET_NAME.test(name)) {\n throw new Error(\n `foldkit-media/vite: \"${name}\" is not a set name (lowercase words and hyphens).`,\n )\n }\n }\n const twice = [...iconify, ...folders.map(([name]) => name)].find(\n (name, at, all) => all.indexOf(name) !== at,\n )\n if (twice !== undefined) throw new Error(`foldkit-media/vite: the set \"${twice}\" is given twice.`)\n\n let root = process.cwd()\n const read = new Map<string, ReadSet>()\n const folderDirs = new Map(folders)\n const folderOf = (name: string) => resolve(root, folderDirs.get(name)!)\n\n const readIconify = (prefix: string): ReadSet => {\n const require = createRequire(join(root, 'package.json'))\n let file: string\n try {\n file = require.resolve(`@iconify-json/${prefix}/icons.json`)\n } catch {\n throw new Error(\n `foldkit-media/vite: the Iconify set \"${prefix}\" is not installed: add @iconify-json/${prefix}.`,\n )\n }\n let set: IconifySet\n try {\n set = Schema.decodeUnknownSync(IconifySet)(JSON.parse(readFileSync(file, 'utf8')))\n } catch (error) {\n throw new Error(\n `foldkit-media/vite: ${file} is not an Iconify set: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n const icons: Array<readonly [string, IconData]> = []\n const refused: Array<readonly [string, string]> = []\n // The icon each name draws in the end, through its aliases.\n const drawn = (name: string): string => {\n let current = name\n for (\n let step = 0;\n step < 16 && set.aliases !== undefined && Object.hasOwn(set.aliases, current);\n step++\n )\n current = set.aliases[current]!.parent\n return current\n }\n // Which icon each export name already stands for.\n const exported = new Map<string, string>()\n for (const name of namesOf(set)) {\n // An alias spelt only differently from the icon it names (Lucide's\n // `arrow-down-01` for `arrow-down-0-1`) would be imported by the same\n // name as that icon, and it is that icon: leave the alias out. Two\n // different icons under one name still fail, in `named`.\n const as = exportName(name)\n if (exported.get(as) === drawn(name)) continue\n exported.set(as, drawn(name))\n try {\n icons.push([name, fromIconify(set, name)])\n } catch (error) {\n refused.push([name, error instanceof Error ? error.message : String(error)])\n }\n }\n return { icons: named(prefix, icons), refused }\n }\n\n const readFolder = (name: string): ReadSet => {\n const folder = folderOf(name)\n const files = readdirSync(folder)\n .filter(file => extname(file) === '.svg')\n .sort()\n return {\n icons: named(\n name,\n files.map(file => {\n const path = join(folder, file)\n return [\n file.slice(0, -4),\n parse(readFileSync(path, 'utf8'), relative(root, path)),\n ] as const\n }),\n ),\n refused: [],\n }\n }\n\n const setOf = (name: string): ReadSet => {\n const known = read.get(name)\n if (known !== undefined) return known\n const made = iconify.includes(name) ? readIconify(name) : readFolder(name)\n read.set(name, made)\n return made\n }\n\n const all = () => [...iconify, ...folders.map(([name]) => name)]\n\n const writeDeclaration = () => {\n if (options.dts === false) return\n const path = resolve(root, options.dts ?? 'foldkit-icons.d.ts')\n const text = declarationOf(new Map(all().map(name => [name, setOf(name)])))\n let current: string | undefined\n try {\n current = readFileSync(path, 'utf8')\n } catch {\n current = undefined\n }\n // Written only when it changes, so a watcher on the file does not see a write of every build.\n if (current !== text) writeFileSync(path, text)\n }\n\n return {\n name: 'foldkit-media:icons',\n configResolved(config) {\n root = config.root\n },\n buildStart() {\n read.clear()\n writeDeclaration()\n for (const [name] of folders) this.addWatchFile(folderOf(name))\n },\n resolveId(id) {\n if (!id.startsWith(PREFIX)) return undefined\n const name = id.slice(PREFIX.length)\n if (!all().includes(name)) {\n throw new Error(\n `foldkit-media/vite: there is no icon set \"${name}\"; the sets given are ${all().join(', ') || 'none'}.`,\n )\n }\n return `${RESOLVED}${name}`\n },\n load(id) {\n if (!id.startsWith(RESOLVED)) return undefined\n const name = id.slice(RESOLVED.length)\n if (folders.some(([folder]) => folder === name)) {\n for (const file of readdirSync(folderOf(name)))\n this.addWatchFile(join(folderOf(name), file))\n }\n return moduleOf(setOf(name))\n },\n configureServer(server) {\n const dirs = folders.map(([name]) => [name, folderOf(name)] as const)\n server.watcher.add(dirs.map(([, dir]) => dir))\n server.watcher.on('all', (_, file) => {\n const changed = dirs.find(([, dir]) => {\n const path = relative(dir, file)\n return !isAbsolute(path) && !path.startsWith('..')\n })\n if (changed === undefined || extname(file) !== '.svg') return\n read.delete(changed[0])\n try {\n writeDeclaration()\n } catch (error) {\n // A throw here would end the server; the set's next load fails with it, where the page shows it.\n server.config.logger.error(error instanceof Error ? error.message : String(error))\n }\n for (const environment of Object.values(server.environments)) {\n const module = environment.moduleGraph.getModuleById(`${RESOLVED}${changed[0]}`)\n if (module !== undefined) environment.moduleGraph.invalidateModule(module)\n }\n server.ws.send({ type: 'full-reload' })\n })\n },\n }\n}\n\nexport { images, type ImagesOptions } from './images.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,QAAQ;AAKd,MAAM,iBAAiB;AACvB,MAAM,aAAa;AACnB,MAAM,WAAW;;AAgBjB,MAAM,aAAa,QAAuB,UAAyC,CACjF,GAAG,OAAO,OAAO,QAAO,UAAS,QAAQ,KAAK,GAC9C,KACF;;;;;AAMA,MAAM,OAAO,OAAO,MAAc,UAA+B;CAC/D,MAAM,UAAU,GAAG,KAAK,GAAG,WAAW,EAAE;CACxC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