/** * docx Phase 4 — inline images: add PNG/JPEG pictures and list existing * ones. * * OWNERSHIP (DESIGN-P4.md): this file + images.test.ts belong to the * IMAGES agent. Allowed imports: ./internal.js, ../xml, ../mce, * ../schema. Never import ./index.js or another feature module. * * Scope (DESIGN-P4.md non-goals): INLINE images only (wp:inline inside * w:drawing) — floating/anchored (wp:anchor) creation is a later phase; * existing anchored images are preserved untouched and listed read-only. * Formats: PNG and JPEG, detected by magic-byte sniffing — never by a * caller-supplied name or extension. */ import { type DocumentInternal } from './internal.js'; /** EMUs per CSS pixel at 96 DPI (914400 EMU/inch ÷ 96 px/inch). */ export declare const EMU_PER_PIXEL = 9525; /** * Convert 96-DPI pixels to EMUs (rounded to the nearest integer EMU). * * @example * pxToEmu(300); // 2857500 */ export declare function pxToEmu(px: number): number; /** * Convert EMUs to 96-DPI pixels. * * @example * emuToPx(2857500); // 300 */ export declare function emuToPx(emu: number): number; /** Image formats this phase understands (sniffed from bytes). */ export type ImageFormat = 'png' | 'jpeg'; /** * Display-size options for {@link addImage}. Give EMU or px, not both * spellings of the same axis (that throws — "which one did you mean?"). * Omitted axes are derived from the image's intrinsic pixel size at * 96 DPI, preserving aspect ratio when exactly one axis is given. */ export interface AddImageOptions { widthEmu?: number; heightEmu?: number; /** Convenience: width in 96-DPI pixels (converted via pxToEmu). */ widthPx?: number; /** Convenience: height in 96-DPI pixels. */ heightPx?: number; /** Alt text (wp:docPr/@descr) — accessibility; default ''. */ altText?: string; } /** One image in the document (returned by {@link listImages} / {@link addImage}). */ export interface ImageInfo { /** The media part holding the bytes, e.g. '/word/media/image1.png'. */ readonly partName: string; /** Sniffed format of the media part's bytes. */ readonly format: ImageFormat; /** Display width in EMU (wp:extent/@cx). */ readonly widthEmu: number; /** Display height in EMU (wp:extent/@cy). */ readonly heightEmu: number; /** Alt text (wp:docPr/@descr), '' when none. */ readonly altText: string; /** How the image sits: 'inline' (wp:inline) or 'anchored' (wp:anchor, read-only). */ readonly placement: 'inline' | 'anchored'; /** * The image bytes (async — the media part may need decompressing). * * @example * const png = await img.data(); */ data(): Promise; } /** * Append a paragraph containing one inline image: sniffs PNG/JPEG from * the magic bytes (anything else throws, naming the accepted formats), * reads the intrinsic pixel size from the image header (PNG IHDR / JPEG * SOF) for default sizing, stores the bytes as a new /word/media part, * adds the image relationship, and builds the * w:p > w:r > w:drawing > wp:inline (wp:extent, wp:docPr with a * document-unique id via nextDrawingId, a:graphic > pic:pic with * a:blip/@r:embed) markup. Marks the main part dirty. * * @example * const img = addImage(di, pngBytes, { widthPx: 300, altText: 'Chart' }); * img.partName; // '/word/media/image1.png' */ export declare function addImage(di: DocumentInternal, bytes: Uint8Array, options?: AddImageOptions): ImageInfo; /** * Every image in the main document body in document order (inline and * anchored), resolved through a:blip/@r:embed to its media part. * Drawings whose relationship dangles are skipped (never a throw on * read), as are media parts that are neither PNG nor JPEG (WMF/EMF and * friends — outside this phase's {@link ImageFormat} model). A fresh * array per call; reading never mutates anything (L3 stays intact). * * @example * for (const img of listImages(di)) console.log(img.partName, img.widthEmu); */ export declare function listImages(di: DocumentInternal): readonly ImageInfo[]; //# sourceMappingURL=images.d.ts.map