/** * Wire-stable annotation primitives that are not pure geometry. * * Geometry primitives (points, rects, sizes, quads, rotation) now live in * `../geometry` as the canonical `Pdf*` vocabulary. The aliases below are * transitional re-exports kept only so existing consumers keep compiling * during the geometry consolidation; new code should import `Pdf*` directly * from `../geometry`. * * These do not depend on PDFium or any browser/Node surface; they are * the lingua franca between local engine, cloud engine, and server. */ /** * An sRGB color as `'#rrggbb'`: lowercase when the engine gives one, either * case when it takes one. A gray or CMYK color in the file reads as its sRGB * equivalent, and sent back unchanged it stays as the file has it. * * A color carries no alpha: transparency is the separate `opacity` field * (`/CA`), so there is one source of truth for it. */ export type Color = string; /** * /LE entries (line endings). Maps PDFium FPDFAnnot_GetLineEndings codes * onto the spec names. We use kebab-case so the wire format is stable * across language ports. */ export type LineEnding = | 'none' | 'square' | 'circle' | 'diamond' | 'open-arrow' | 'closed-arrow' | 'butt' | 'r-open-arrow' | 'r-closed-arrow' | 'slash'; /** * The `/LE` pair carried by line and polyline annotations: the ending * drawn at the start point and the ending drawn at the end point. */ export interface LineEndings { start: LineEnding; end: LineEnding; } /** * The 14 standard PDF fonts a free-text annotation's `/DA` can name. We use * kebab-case so the wire format is stable across language ports; the engine * maps these onto PDFium's `FPDF_STANDARD_FONT` integer codes at write time. */ export const STANDARD_FONTS = [ 'courier', 'courier-bold', 'courier-bold-oblique', 'courier-oblique', 'helvetica', 'helvetica-bold', 'helvetica-bold-oblique', 'helvetica-oblique', 'times-roman', 'times-bold', 'times-bold-italic', 'times-italic', 'symbol', 'zapf-dingbats', ] as const; export type StandardFont = (typeof STANDARD_FONTS)[number]; /** * What a `fontFamily` names (free text, form widgets, redaction labels): the * `name` of a font in `doc.fonts.list()`. One of the 14 {@link StandardFont} * names, the key of one of the engine's fonts (registered locally, the * server's on the cloud), or a document font's name (its PostScript name). * * The `(string & {})` arm keeps the standard-font literals auto-completing * while still accepting any other name. The standard names are matched * first, so they're reserved: no engine font can be keyed `'helvetica'`. */ export type FontName = StandardFont | (string & {}); /** * Horizontal text alignment (`/Q`) for free-text annotations. Maps onto the * ISO 32000 §12.7.3.3 quadding codes 0/1/2 at write time. */ export type TextAlignment = 'left' | 'center' | 'right'; /** * Free-text `/IT` intent. `free-text` is a plain text box; `free-text-callout` * adds a `/CL` leader line pointing at the called-out region; * `free-text-typewriter` is a typewriter box another app made, read and kept * but not created. */ export type FreeTextIntent = 'free-text' | 'free-text-callout' | 'free-text-typewriter'; /** Where a free text's lines sit in its box, top to bottom. */ export type VerticalAlignment = 'top' | 'middle' | 'bottom'; /** Caret `/IT` intent used by an Acrobat-compatible replace-text edit. */ export type CaretIntent = 'replace'; /** Strikeout `/IT` intent used by the subordinate part of a replace-text edit. */ export type StrikeoutIntent = 'strikeout-text-edit'; /** Ink `/IT` intent used by an Acrobat-compatible freehand highlighter. */ export type InkIntent = 'ink-highlight'; /** * Effective blend mode of an annotation's normal appearance stream (`/AP /N`). * Values use CSS-compatible kebab-case so the wire vocabulary is portable; the * engine maps them onto PDFium's `FPDF_BLENDMODE` integer codes. */ export type BlendMode = | 'normal' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity'; /** * Border/line style for shape annotations — the `/BS /S` (border style) * subset PDFium can author. Maps onto the ISO 32000 §8.4.3.3 border style * names. Cloudy borders are a separate concern (`/BE` border effect), * surfaced as `cloudyIntensity` on the shape DTO, not as a border style. * * kebab-/lower-case so the wire format is stable across language ports; * the engine maps these onto PDFium's integer codes at write time. */ export type AnnotationBorderStyle = 'solid' | 'dashed' | 'beveled' | 'inset'; /** * A form widget's border (`/BS /S`): the four annotation styles, and * `underline`, a line along the bottom only, which only a widget draws. */ export type WidgetBorderStyle = AnnotationBorderStyle | 'underline'; /** * A symbol a checkbox or radio button shows while it's on (`/MK /CA`, a * ZapfDingbats character). Without one, a checkbox shows a check and a radio * button a circle. */ export type WidgetCheckStyle = 'check' | 'cross' | 'star' | 'circle' | 'square' | 'diamond'; /** The border styles an annotation other than a widget draws: `beveled` and `inset` are read, not written. */ export type DrawnBorderStyle = Extract; /** * The `/RT` (reply type) relationship an annotation declares toward the * annotation its `/IRT` points at (ISO 32000 §12.5.6.2). Wire-stable * kebab/lower-case strings; the engine maps these onto PDFium's * `FPDF_ANNOT_REPLY_TYPE` integer codes at read/write time. * * 'reply' -> `/R` a comment-thread reply (the ISO default when * `/IRT` is present but `/RT` is absent). * 'group' -> `/Group` a subordinate part of one logical annotation * group (e.g. the StrikeOut of a replace-text pair, * grouped under its Caret). */ export type AnnotationReplyType = 'reply' | 'group'; /** The two ISO 32000 §12.5.6.3 standard state models (Table 174). */ export type KnownAnnotationStateModel = 'review' | 'marked'; /** * The `/StateModel` of an annotation-state text annotation — * ISO 32000 §12.5.6.3. The standard models are `'review'` and `'marked'`, but the * PDF stores the entry as a free text string and Acrobat supports * registering custom state models, so the type stays open. The * `(string & {})` arm keeps the standard literals auto-completing while * accepting any custom model (the {@link FontName} pattern). * * Known values are wire-stable lowercase; the engine maps them onto the * capitalized PDF spellings (`Review`, `Marked`) at read/write time. * Unknown values round-trip verbatim in both directions. */ export type AnnotationStateModel = KnownAnnotationStateModel | (string & {}); /** The ISO 32000 §12.5.6.3 standard states (Table 174). */ export type KnownAnnotationState = | 'accepted' | 'rejected' | 'cancelled' | 'completed' | 'none' | 'marked' | 'unmarked'; /** * The `/State` an annotation-state text annotation sets — * ISO 32000 §12.5.6.3. `'accepted' | 'rejected' | 'cancelled' | 'completed' | * 'none'` belong to the `'review'` model; `'marked' | 'unmarked'` to the * `'marked'` model. Open for the same reason as * {@link AnnotationStateModel}: custom models bring custom states. * * States are per user and live on separate text annotations replying * (`/IRT`) to their target — never on the target itself. The `/T` of the * state annotation names who set it; later changes by the same user * chain as replies to their previous state annotation, latest wins. */ export type AnnotationState = KnownAnnotationState | (string & {}); /** * Bitset wrapper for the `/F` (Annotation Flags) PDF entry. We expose each * bit as its own boolean so callers don't have to know the bit positions. */ export interface AnnotationFlags { invisible: boolean; hidden: boolean; print: boolean; noZoom: boolean; noRotate: boolean; noView: boolean; readOnly: boolean; locked: boolean; toggleNoView: boolean; lockedContents: boolean; } export const NO_ANNOTATION_FLAGS: AnnotationFlags = { invisible: false, hidden: false, print: false, noZoom: false, noRotate: false, noView: false, readOnly: false, locked: false, toggleNoView: false, lockedContents: false, };