import type { PostextConfig, Resource } from '../types.js'; import { type TraceContourOptions } from '../contour/index.js'; import type { BundleBlob, BundleCanvasScope, BundleChapter, BundleFileReader, BundleFontFile, BundleIdScheme, BundleImageSize, BundleManifest, BundleManifestV2, BundleStart } from './types.js'; /** The configuration a bundle's own `config` is laid over: the default * colour palette plus the built-in resource types localised to `locale` * (what the Sandbox starts every document from). */ export declare function bundleBaseConfig(locale?: string): PostextConfig; export interface ReadBundleOptions { /** Locale to read a bilingual bundle in. Defaults to the manifest's own * locale, else `en`. */ locale?: string; /** How loaded files are named (`fileId`). Defaults to their path. */ ids?: BundleIdScheme; /** Configuration under the manifest's `config`. Defaults to * `bundleBaseConfig()` in the language of the bundle * (`resolveBundleConfigLocale(manifest, locale)`: the locale it serves, * or the language its `config` names when the manifest names none), so * a bundle in one language gets resource types in that language, * whatever `locale` asks for. A host that passes its own base should * localise it to the same language. It is taken in today's terms, with * one exception: under a manifest older than `CONFIG_VERSION`, the pins * its stamp calls for (see `migrateBundleConfig`) also apply to the keys * of the base that the manifest and the locale leave in force, all but * the heading breaks, since the old reader laid the bundle out with * them too: a base `math` is pinned with the bundle's maths size * (`fontSizeScale` × `LEGACY_MATH_SIZE`), a base `layout` with its * inline gap, a base `bodyText` with its dash breaks, and so on, each * under the same conditions on the chapters and the configuration as a * key of the manifest. */ baseConfig?: PostextConfig; /** Intrinsic size of an SVG whose spec omits it. Defaults to `svgSize`. */ measureSvg?: (markup: string) => BundleImageSize | undefined; /** Intrinsic size of a bitmap whose spec omits it, and the resolution * its file states when there is one (`BundleImageSize.resolution`). * Defaults to reading the image header (`bitmapInfo`). */ measureBitmap?: (bytes: ArrayBuffer, mime: string) => Promise | BundleImageSize | undefined; /** Read each bitmap's resolution from its file into * `Resource.bitmap.fileResolution` when its spec gives none (#631). * Defaults to true when the bundle's `layout.bitmapResolution` is * `'file'`, the one policy that lays the pictures out by it; else the * resources come back as the manifest declares them. */ readResolution?: boolean; onWarning?: (message: string) => void; /** Trace the alpha channel of the pictures a contour wrap runs round * (#883) into `contour.traced`: those whose `contour` is set or whose * placement (or type) says `wrap: 'contour'`, and every bitmap when a * page template has a frame with `wrap: 'contour'`. Default `true`. */ traceContours?: boolean; /** Decode a picture the engine does not read itself (a WebP, a GIF) for * the trace (see `traceResourceContour`). */ decodeContour?: TraceContourOptions['decode']; } export interface ReadBundleResult { manifest: BundleManifest; /** The locale the content was resolved for (the chapter-map key a * bilingual bundle served, else the manifest's locale, else the one * asked for). */ locale: string; chapters: BundleChapter[]; /** Base config + manifest `config` + the locale's overrides, with the * bundle's font families appended to `customFonts`. A manifest stored * under older rules than `CONFIG_VERSION` (none: postext 1.4 or earlier) * is read in today's terms (see `migrateBundleConfig`): every pin its * stamp calls for, from the heading breaks and the maths size of 1.4 on, * keeps what that version laid out (most only when the chapters show * something they are for). The layout fixes that no pin holds back apply to it as to any * book. */ config: PostextConfig; /** The book's general settings (#1209), for a bundle in several * languages: the base config and the manifest's `config` without the * locale's override, read under the same rules and with the same * fonts. An editor keeps it as the layer every edition shares and the * difference to `config` as this language's own. */ sharedConfig?: PostextConfig; resources: Resource[]; /** Resource payloads (pictures and PDF print masters). */ blobs: BundleBlob[]; fonts: BundleFontFile[]; /** Where the book starts, for a bundle that holds part of a longer one * (the manifest's `start`, or the locale's own): the `continuation` of * the first chapter. Absent for a book that starts at its beginning. */ start?: BundleStart; } /** Read a manifest plus its files. Throws on an invalid manifest or a * missing chapter, picture or font file. The configuration of a manifest * stored under older rules than `CONFIG_VERSION` (none: postext 1.4 or * earlier) keeps what that version laid out: the pins its stamp calls for * (see `migrateBundleConfig`) apply to the manifest, the locale's * overrides and the keys of the base they leave in force (all but the * heading breaks). */ export declare function readBundle(manifest: unknown, readFile: BundleFileReader, options?: ReadBundleOptions): Promise; export interface BundleMeta { id: string; name: string; description?: string; locale?: string; } /** What another locale of a bilingual bundle brings on top of the shared * content (see {@link BundleContent.localized}). */ export interface BundleLocaleContent { /** The book's title in this language, written as `localized[…].name` * when it is not the shared `name` (#891). */ name?: string; /** The description in this language, likewise. */ description?: string; /** The locale's own chapters, in book order. Absent: it reads the * shared (primary) chapters. */ chapters?: readonly { title: string; markdown: string; }[]; /** The locale's configuration: its top-level keys over the shared * configuration's (or, with `BundleContent.sharedConfig`, the whole * configuration of the edition). Written as an override of the fields * that differ from the shared settings, merged over them field by field * when read (#1209). Fonts are shared: the families of `customFonts` * join the bundle's. */ config?: PostextConfig; /** The locale's wording and artwork of the shared resources, merged by * id: `caption`, `note`, `altText`, `table`, and a picture of its own * (`bitmap.fileId` / `svg.fileId`, `svg.pdfFileId`) when the artwork * carries words. Other fields are shared; an id that is not among the * resources is left out with a warning. */ resources?: readonly (Pick & Partial)[]; /** Where the locale's edition starts, when not where the shared one * does (see {@link BundleContent.start}). */ start?: BundleStart; } export interface BundleContent { chapters: readonly { title: string; markdown: string; }[]; /** The primary edition's configuration. */ config: PostextConfig; /** The book's general settings (#1209), when they are not the primary * edition's: written as the manifest's `config`, and every edition, the * primary included (`BundleMeta.locale`), as an override over them * (`localized[…].config`). `config` and each `localized[…].config` are * then whole configurations. Absent, the primary's `config` is the * shared one. */ sharedConfig?: PostextConfig; resources: readonly Resource[]; /** Written as the manifest's `view` when it is not the default. */ canvasScope?: BundleCanvasScope; /** The cover picture, carried as the manifest's `thumbnail`. */ thumbnail?: { fileId: string; mime: string; }; /** Where the book starts, for a bundle that holds part of a longer one: * the `continuation` its first chapter is laid out with, written as the * manifest's `start`. Left out, or empty, nothing is written. */ start?: BundleStart; /** Other locales of a bilingual bundle, by locale tag (`es`, `pt-BR`); * `chapters`, `config` and `resources` are then the primary locale's * (`BundleMeta.locale`, required). Written as the manifest's `locales`, * a locale → chapters map (when any locale has chapters of its own) and * `localized`. */ localized?: Record; } export interface PlannedFile { /** Path inside the bundle (`resources/x.png`, `fonts/y.ttf`). */ path: string; fileId: string; kind: 'blob' | 'font'; /** Resource id (blob) or family name (font), for warnings. */ owner: string; /** Set on a picture only one locale reads (its own artwork). */ locale?: string; } export interface BundlePlan { manifest: BundleManifestV2; files: PlannedFile[]; /** Chapter file path → text, in book order (index-aligned with the * content's chapters). */ chapterFiles: { path: string; markdown: string; }[]; /** The paths of the chapters a locale has of its own (`localized[…]` with * `chapters`), in book order, by locale: what a host that writes a * pagination file per language (`layouts..json`) keys it by. * Absent for a locale that reads the primary chapters. */ localeChapterFiles?: Record; warnings: string[]; } /** * Trace the alpha channel of the bitmaps a contour wrap runs round (#883): * those with a `contour`, or whose placement or type wraps by contour, and * all of them when a frame of the configuration does. A picture whose * trace is already there (this file, this threshold) keeps it. */ export declare function traceBundleContours(resources: Resource[], blobs: readonly BundleBlob[], config: PostextConfig, options?: TraceContourOptions): Promise; /** Font formats a bundle may carry (`.woff` is rejected by the PDF backend * and by `fontsToCustomFonts`). */ export declare const EXPORTABLE_FONT_FORMATS: readonly ["ttf", "otf", "woff2"]; /** Decide file names and the manifest for a bundle. Pure; the bytes are * resolved by `resolveBundleFiles`. Fonts are declared in `fonts[]`, * never inside `config.customFonts` (their ids are local to the writer). */ export declare function planBundle(meta: BundleMeta, content: BundleContent): BundlePlan; export interface BundleByteSources { readBlob: (fileId: string) => Promise; readFont: (fileId: string) => Promise; } export interface ResolvedBundleFiles { /** Path → bytes, ready to zip (`preset.json` and chapters included). */ files: Record; manifest: BundleManifestV2; warnings: string[]; /** Planned paths whose bytes could not be read (and were dropped). */ missing: string[]; } /** Resolve a plan's bytes. A resource whose payload is gone is dropped from * the manifest (a spec without a file would come back as a broken * figure); a font variant whose file is gone is dropped likewise, and its * family with it when nothing remains. */ export declare function resolveBundleFiles(plan: BundlePlan, sources: BundleByteSources): Promise; //# sourceMappingURL=codec.d.ts.map