UNPKG

dropflow

Version:

A small CSS2 document renderer built from specifications

175 lines (174 loc) 5.83 kB
import { Logger } from './util.js'; import { Style } from './style.js'; import { Run } from './layout-text.js'; import { Break, Inline, IfcInline, BlockContainer } from './layout-flow.js'; export interface LogicalArea { blockStart: number | undefined; lineLeft: number | undefined; blockSize: number | undefined; inlineSize: number | undefined; } export interface RenderItemLogOptions { containingBlocks?: boolean; css?: keyof Style; paragraphText?: string; bits?: boolean; } export declare abstract class RenderItem { style: Style; constructor(style: Style); isBlockContainer(): this is BlockContainer; isRun(): this is Run; isInline(): this is Inline; isBreak(): this is Break; isIfcInline(): this is IfcInline; isBox(): this is Box; /** * A layer is a stacking context root or an element that CSS 2.1 appendix E * says to treat like one. */ isLayerRoot(): boolean; /** * Does this paint anything in the background layer? Borders, box-shadow, etc. */ hasBackground(): boolean; /** * Does this paint anything in the foreground layer? Text, images, etc. */ hasForeground(): boolean; /** * There is a background in some descendent that is part of the same paint * layer (not necessarily in the subject). (See also isLayerRoot). * * A background is a background-color or anything CSS 2.1 appendix E groups * with it. */ hasBackgroundInLayerRoot(): boolean; /** * There is a foreground in some descendent that is part of the same paint * layer (not necessarily in the subject). (See also isLayerRoot). * * A foreground is a text run or anything CSS 2.1 appendix E groups with it */ hasForegroundInLayerRoot(): boolean; /** * There is a background somewhere beneath this node * * A background is a background-color or anything CSS 2.1 appendix E groups * with it */ hasBackgroundInDescendent(): boolean; /** * There is a foreground somewhere beneath this node * * A foreground is a text run or anything CSS 2.1 appendix E groups with it */ hasForegroundInDescendent(): boolean; abstract logName(log: Logger, options?: RenderItemLogOptions): void; abstract getLogSymbol(): string; log(options?: RenderItemLogOptions, log?: Logger): void; /** * Typically the time to shape text and gather font metrics */ prelayout(): void; /** * Typically the time to absolutize relative coordinates */ postlayoutPreorder(): void; /** * Typically the time to snap pixels */ postlayoutPostorder(): void; } export declare class Box extends RenderItem { id: string; children: RenderItem[]; containingBlock: BoxArea; /** * General boolean bitfield shared by all box subclasses. The bits labeled * with "has" say something about their content to allow for optimizations. * They propagate through to parents of the same type, though some of them * do so conditionally. */ bitfield: number; /** * Bitfield allocations. Box subclasses with different inheritance are allowed * to overlap attribute bits or propagate target bits. It's easier to keep * these all in one place than try to define them on the subclasses. */ static BITS: { isAnonymous: number; enableLogging: number; reserved1: number; reserved2: number; hasBackgroundInLayer: number; hasForegroundInLayer: number; hasBackgroundInDescendent: number; hasForegroundInDescendent: number; isInline: number; isBfcRoot: number; hasText: number; hasComplexText: number; hasSoftHyphen: number; hasNewlines: number; hasSoftWrap: number; hasCollapsibleWs: number; hasInlines: number; hasPaintedInlines: number; hasPositionedInline: number; hasColoredInline: number; hasSizedInline: number; hasBreaks: number; hasFloats: number; hasInlineBlocks: number; }; /** * Use this, not BITS, for the ctor! BITS are ~private */ static ATTRS: { isAnonymous: number; enableLogging: number; }; static PROPAGATES_TO_INLINE_BITS: number; static BITFIELD_END: number; constructor(style: Style, children: RenderItem[], attrs: number); propagate(parent: Box): void; isBox(): this is Box; isAnonymous(): boolean; isPositioned(): boolean; isStackingContextRoot(): boolean; hasBackgroundInLayerRoot(): boolean; hasForegroundInLayerRoot(): boolean; hasBackgroundInDescendent(): boolean; hasForegroundInDescendent(): boolean; getRelativeVerticalShift(): number; getRelativeHorizontalShift(): number; logName(log: Logger, options?: RenderItemLogOptions): void; getLogSymbol(): string; stringifyBitfield(): string; } export declare class BoxArea { parent: BoxArea | null; box: Box; blockStart: number; blockSize: number; lineLeft: number; inlineSize: number; constructor(box: Box, x?: number, y?: number, w?: number, h?: number); clone(): BoxArea; get writingMode(): import("./style.js").WritingMode; get direction(): import("./style.js").Direction; get x(): number; set x(x: number); get y(): number; set y(y: number); get width(): number; get height(): number; setParent(p: BoxArea): void; inlineSizeForPotentiallyOrthogonal(box: BlockContainer): number; absolutify(): void; snapPixels(): void; repr(indent?: number): string; } export declare function prelayout(root: BlockContainer): void; export declare function postlayout(root: BlockContainer): void;