import { IDML } from './idml.js'; import { ConvertedSerial, ConvertIDML2SerialOptions, ImageGraphicType, RequiredFont } from './idml2serial.js'; import { AssetFile, AggregatedFont, AggregatedImage } from './assets.js'; /** * One image asset the import wizard must handle: its bytes (embedded or from a * provided file), how to display it, and every serial element that references it. */ export type PreparedImage = { imageId: string; linkURI?: string; graphicType: ImageGraphicType; /** true → not browser-renderable (PDF/EPS/WMF/TIFF/PSD); bx-files must convert it. */ needsConversion: boolean; /** true → currently shown in the serial via a blob/data preview src. */ hasPreview: boolean; /** Uploadable bytes: embedded IDML bytes, or a provided file. undefined = still missing. */ bytes?: ArrayBuffer; source: 'embedded' | 'provided' | 'missing'; /** Serial elements (across spreads) whose `image.src` this asset feeds. */ occurrences: { serialIndex: number; elementId: string; }[]; }; /** * Stateful, asset-aware IDML → Serial converter. * * `convertIDML2Serial` is a pure kernel: given an IDML it walks the document and * measures text against whatever fonts happen to be loaded in the ambient canvas. * That last part is the problem — measurement (the ascent baseline shift, auto- * wrap) is font-DEPENDENT, so a convert that runs before the document's fonts are * available bakes wrong geometry that the live renderer can't undo. * * This class makes assets a first-class INPUT instead of an after-the-fact report. * You hand it the IDML plus whatever files you have (a whole `Document fonts/` + * `Links/` package folder, or nothing), it matches them to what the document * needs, and {@link convert} performs the atomic step: resolve → inject fonts → * AWAIT real availability → measure precisely → emit the serial. Providing more * assets later and calling {@link convert} again re-derives the serial from the * new state — the same model bx-studio's import wizard drives by hand today, now * owned by the module so every consumer shares it. * * The kernel stays public and unchanged for callers that don't need any of this. */ export declare class IdmlSerialConverter { private readonly idml; private assets; /** Font/image work list, derived once from a font-independent discovery pass. */ private aggregated; private lastResult; /** Aggregated-image keys that got a preview src in the last convert (for the manifest). */ private previewKeys; /** Blob URLs minted last convert, revoked on the next so a re-convert doesn't leak. */ private previewBlobUrls; private constructor(); /** * Parse the IDML and take stock of what it needs. `files` may be a whole * package folder (fonts, links) — anything unrecognized is simply ignored. */ static create(idmlBytes: ArrayBuffer, files?: AssetFile[]): Promise; /** Register more asset files (later files win on name collision). */ ingest(files: AssetFile[]): void; /** Register a single asset (font or image). Convenience over {@link ingest}. */ provideAsset(file: AssetFile): void; /** Every font the document uses (family + distinct weight/italic variants). */ get requiredFonts(): RequiredFont[]; /** Required fonts with no matching file among the currently-provided assets. */ get missingFonts(): AggregatedFont[]; /** Linked images with neither embedded bytes nor a matching provided file. */ get missingImages(): AggregatedImage[]; /** The current provided-asset set (read-only view). */ get providedAssets(): readonly AssetFile[]; /** * Convert with the current asset set. Injects the resolved fonts and AWAITS * their real availability before measuring, so the geometry is precise on the * first pass — no font-load race. Re-runnable after providing more assets. The * emitted serials carry `fonts[]` (local srcs) so the renderer loads the same * faces; a persisting consumer swaps those for durable URLs at upload time. */ convert(options?: ConvertIDML2SerialOptions): Promise; /** * The complete image work list for an import wizard: every image asset with its * uploadable bytes (embedded or provided), whether it needs bx-files conversion, * whether it currently previews, and the serial elements to patch with the final * durable URL. Images with `source: 'missing'` still need a file from the user. */ get imageManifest(): PreparedImage[]; /** The serials from the most recent {@link convert} (null before the first). */ get result(): ConvertedSerial[] | null; /** The parsed IDML document (e.g. to also run idml2svg over the same instance). */ get document(): IDML; /** * Provided font files matched to a required family, one binary per variant. * * `matchFontFiles` returns exact-metadata-name hits PLUS the family's other files * (a variant's stored file name is sometimes wrong — see matchFontFiles), so for a * multi-weight family every variant sees several candidates. Picking `matched[0]` * blindly gave EVERY weight the same (first) binary — the family collapsed to one * weight at render. Instead: trust an exact file-name hit, else pick the candidate * whose REAL weight/italic (read from the binary via fontkit) matches the variant, * preferring a file not already taken by another variant. */ private facesFor; /** Among candidate binaries, the one whose real weight/italic best fits `variant`. */ private pickFaceByMetrics; private faceMetaCache; private faceMeta; private buildLoadableFonts; private assetForImage; /** * Preview-src provider for displayable images. Compresses each once (blob in the * browser, data URL in Node) and keys it so the kernel can look it up per element: * linked images by their shared linkURI (one blob serves every placement), * embedded images by their sprite id. Returns undefined when nothing is displayable. */ private buildImageResolver; /** * SVG viewBox provider (by linkURI / imageId) for LINKED SVGs — their bytes aren't on the * sprite, so the kernel can't read the viewBox itself. Parse it from the embedded-or-provided * bytes so the crop is placed against the rendered artboard (InDesign's GraphicBounds is the * auto-cropped content bbox). Undefined when no SVG has a resolvable viewBox. */ private buildImageViewBoxResolver; /** Displayable bytes + MIME for one aggregated image: embedded IDML bytes, or a * provided linked file. Undefined for non-displayable formats and unresolved links. */ private resolveDisplayableBytes; } //# sourceMappingURL=converter.d.ts.map