import type { PostextConfig, Resource } from '../types.js'; import type { BundleCanvasScope, BundleChapter, BundleFontFile, BundleManifest, BundleManifestV2, BundleStart } from './types.js'; /** A `.postext` file, opened. Every `fileId` it hands out (in `resources` * and `config.customFonts`) is the file's path inside the bundle, so * `files.get(fileId)` returns its bytes. */ export interface PostextBundle { /** The validated `preset.json`. */ manifest: BundleManifest; id: string; /** The title of the edition read: the manifest's `name`, or the * locale's `localized[…].name` (#891). */ name: string; /** The edition's description, likewise. */ description?: string; /** The locale the content was read in. */ locale: string; /** Every locale a bilingual bundle carries (the manifest's `locales`). */ locales?: string[]; /** Chapters in book order. */ chapters: BundleChapter[]; /** Ready for `buildDocument`: the base configuration, the bundle's * `config` and the locale's overrides, with `customFonts` naming the * bundle's own font files. */ config: PostextConfig; /** A bundle in several languages: its general settings (#1209), read * under the same rules as `config`; the difference is this language's * own. */ sharedConfig?: PostextConfig; resources: Resource[]; /** The bundle's font files, one per family variant. */ fonts: BundleFontFile[]; /** Every file of the bundle by path (= `fileId`). */ files: Map; /** Path of the cover picture, when the bundle has one. */ thumbnail?: string; /** How the bundle asks to be viewed (`book`: the whole book as one * canvas). */ canvasScope?: BundleCanvasScope; /** Where the book starts, when the bundle holds part of a longer one * (#695): the `continuation` of its first chapter, which `buildBundle` * lays it out with. Absent for a book that starts at its beginning. */ start?: BundleStart; /** Non-fatal problems met while reading (unsupported font files, a * missing print master). */ warnings: string[]; } export interface OpenBundleOptions { /** Locale to read a bilingual bundle in (`es`, `en-GB`). Defaults to the * bundle's own locale. */ locale?: string; } /** Open a `.postext` file. Throws when it is not a zip, has no valid * `preset.json` or misses a file the manifest names. */ export declare function openBundle(input: Uint8Array | ArrayBuffer | Blob, options?: OpenBundleOptions): Promise; /** Bytes a bundle may be given: raw bytes, a buffer, a Blob / File, or a * string (an SVG's markup, a text file). */ export type BundleFileData = Uint8Array | ArrayBuffer | Blob | string; export interface CreateBundleInput { /** Display name (`preset.json`'s `name`). */ name: string; /** Stable identifier; defaults to a slug of `name`. */ id?: string; description?: string; /** The content's language (`en`, `es`, …). */ locale?: string; /** The book, one entry per chapter. A chapter without a title takes the * text of its first `# ` heading. */ chapters?: { title?: string; markdown: string; }[]; /** A single-document book (one chapter). Ignored when `chapters` is set. */ markdown?: string; config?: PostextConfig; /** The book's general settings, for a bundle in several languages * (#1209): written as the shared `config`, and `config` and every * `localized[…].config` (each then the whole configuration of its * edition) as an override of the fields that differ, merged over them * field by field when read (`mergeConfigLayers`). Absent, `config` is * the shared configuration and each locale's top-level keys go over * it. */ sharedConfig?: PostextConfig; /** Resources; a picture names its payload by `bitmap.fileId` / * `svg.fileId` (and `svg.pdfFileId`), looked up in `files`. */ resources?: Resource[]; /** Payloads by `fileId`: the pictures `resources` reference and the font * files `config.customFonts` variants reference. */ files?: Record | Map; /** Cover picture (PNG, JPEG, WebP, GIF or SVG). */ thumbnail?: { data: BundleFileData; mime: string; }; /** Ask viewers to lay the whole book out as one canvas. */ canvasScope?: BundleCanvasScope; /** Where the book starts, for a bundle that holds part of a longer one * (#695): the `continuation` a single document would be built with * (`{ pageIndexOffset: 57, pageNumbering: { startAt: 58 }, headings: { * h1: 3 } }`: page 58, a verso, in chapter 4). Written as `preset.json`'s * `start`; `openBundle` returns it and `buildBundle` lays the first * chapter out with it. */ start?: BundleStart; /** Modification date written on every file of the archive. Unset: the * time of the call, so two calls with the same input give different * bytes. A fixed date built from local fields (`new Date(1980, 0, 1)`) * makes the output byte-stable on every machine, for hashing or * comparing bundles. See `ZipBundleOptions.mtime` for the dates a zip * can hold and why a timestamp differs between time zones. */ mtime?: Date | number | string; /** More languages of the same book, by locale tag (`es`, `pt-BR`): a * bilingual bundle that `openBundle(bytes, { locale })` reads in any of * them. `chapters`, `config` and `resources` above are then the content * of `locale`, which is required. */ localized?: Record; } /** One more language of a bundle (see {@link CreateBundleInput.localized}). */ export interface CreateBundleLocale { /** The book's title in this language, written as `localized[…].name` * when it differs from `name` (#891). */ name?: string; /** The description in this language (`localized[…].description`). */ description?: string; /** The book in this language, one entry per chapter (a chapter without * a title takes its first `# ` heading). Absent: the locale reads the * primary chapters. */ chapters?: { title?: string; markdown: string; }[]; /** Configuration for this language. Each top-level key replaces the * shared one wholesale when the bundle is read in the locale; keys left * out, or equal to the shared ones, are shared. A full configuration * works as well as the few keys that change. */ config?: PostextConfig; /** Wording and artwork of the shared resources in this language, matched * by `id`: `caption`, `note`, `altText`, a table's `table`, and a picture * of its own (`bitmap.fileId` / `svg.fileId`, `svg.pdfFileId`, looked up * in `files`) when the artwork carries words. Other fields are shared. */ resources?: (Pick & Partial)[]; /** Where this language's edition starts, when not where the primary one * does (a right-bound edition that opens on the other side). */ start?: BundleStart; } export interface CreatedBundle { /** The `.postext` file. */ bytes: Uint8Array; /** The manifest written as `preset.json`. */ manifest: BundleManifestV2; /** Path → bytes of every file inside the archive. */ files: Record; /** What was left out (a missing payload, a `.woff` face, a font family * marked not redistributable). */ warnings: string[]; } /** Write a `.postext` file from a document: its chapters, configuration, * resources and the payloads they reference. */ export declare function createBundle(input: CreateBundleInput): Promise; /** Media type of a file inside a bundle (for a Blob, an object URL). */ export declare function bundleFileMime(path: string): string; //# sourceMappingURL=api.d.ts.map