import { DesignDocument, DesignElement } from "./types.js"; import { CSSTransformStyle } from "@open-pencil/scene-graph/css"; import { SceneGraph, SceneNode } from "@open-pencil/scene-graph"; import { Rect } from "@open-pencil/scene-graph/primitives"; //#region src/import/box.d.ts /** The padding and borders between an element's border box and its content box, per side. */ interface ContentInsets { top: number; right: number; bottom: number; left: number; } //#endregion //#region src/import/image-fills.d.ts /** * A background picture to place once its layer has its final size, where its `background-size` * and `background-position` put it: see `placeBackgroundPictures`. */ interface BackgroundPicture { nodeId: string; imageHash: string; /** The picture's own size, in pixels. */ width: number; height: number; size: string; position: string; /** How far inside the layer's edges the box `background-origin` positions the picture in is. */ origin: ContentInsets; /** How far inside the layer's edges the box `background-clip` paints the picture in is. */ clip: ContentInsets; } //#endregion //#region src/import/placement.d.ts /** * Where the engine that styled the document laid a layer out. For text, `box` is the box its * lines stack in, `lines` how many there are, and `extent` the box the words themselves take. */ interface CapturedBox { box: Rect; lines?: number; extent?: Rect; } /** Captured boxes by the id of the layer built for them. */ type CapturedBoxes = Map; /** * Compares laid-out layers with where the page laid their elements out, and keeps auto layout * only where it reproduces them: a layer of the wrong size takes its captured size, and a * container whose children land elsewhere places them at their captured boxes instead. Sizes come * first: a child a little too large moves the siblings after it, and fixing its size keeps its * parent's auto layout, so children are placed only once no layer changes how it sizes. Returns * how many layers changed, so the caller lays out again until none do. */ declare function placeLayersFromLayout(graph: SceneGraph, boxes: CapturedBoxes): number; //#endregion //#region src/import/stacking.d.ts /** A child the parent paints out of tree order, by its `z-index`. */ interface StackedChild { id: string; z: number; } /** * A container whose positioned children paint in `z-index` order, recorded when its children are * made and applied once layout has sized them, by `applyStacking`. */ interface Stacking { parentId: string; /** Whether the parent is a stacking context, which keeps negative layers above its background. */ isContext: boolean; children: StackedChild[]; } /** Stacking orders by the container each is for. */ type Stackings = Stacking[]; /** * Puts each container's children in the order CSS paints them: negative layers first, lowest * first, then the boxes in the flow as they were, then positioned ones, lowest first and in tree * order at the same level. A container that is not a * stacking context paints its negative layers under its own background, which a layer's fills * cannot go under, so its fills move to a layer of their own above those children. */ declare function applyStacking(graph: SceneGraph, stackings: Stackings): void; //#endregion //#region src/import/transform.d.ts /** An element's transform properties and the origin they transform about. */ interface CSSTransform extends CSSTransformStyle { origin?: string; } /** Transforms by the id of the layer built for their element. */ type CSSTransforms = Map; /** * Applies the elements' transforms to their layers once they are laid out, as CSS transforms * elements after it lays them out. */ declare function applyCSSTransforms(graph: SceneGraph, transforms: CSSTransforms): void; //#endregion //#region src/import/pictures.d.ts /** What an `` shows: a raster image's bytes, or an SVG's markup. */ type ImagePicture = { kind: 'raster'; bytes: Uint8Array; } | { kind: 'svg'; markup: string; }; /** * The picture an `` shows: the one its runtime loaded, or the one its `src` holds as a data * URL. A PNG, JPEG, GIF, WebP, or AVIF is a raster image by its header; SVG is SVG by its media * type, as a browser shows SVG in an image only when it is served as `image/svg+xml`. Null for an * element that is no image or shows nothing it can draw. */ declare function imagePicture(element: DesignElement): ImagePicture | null; /** SVG an element draws, and for a mask, the color its shapes take. */ interface ElementSVG { markup: string; /** The element's background, which shows through a mask's shapes and nowhere else. */ paint?: string; } /** The SVG an element draws: the picture an `` shows, or the mask its background shows through. */ declare function elementSVG(element: DesignElement): ElementSVG | null; //#endregion //#region src/import/background-placement.d.ts /** * Places background pictures where their `background-size` and `background-position` put them, * once their layers have their final size: in the box `background-origin` names, painted within * the one `background-clip` names. A picture that covers the whole layer is a fill cropped to it. * One that covers part of it, such as an icon or an illustration at one side, is a layer of its * own behind the layer's children, as large as the part that shows: a fill cannot leave the rest * of the layer empty. */ declare function placeBackgroundPictures(graph: SceneGraph, pictures: readonly BackgroundPicture[]): void; //#endregion //#region src/import/scene-graph.d.ts interface DesignDocumentToSceneGraphOptions { pageName?: string; } /** Layers built from a styled document, with the boxes its layout was captured at. */ interface DesignLayers { graph: SceneGraph; /** Empty unless the document's layout was recorded; see `placeLayersFromLayout`. */ boxes: CapturedBoxes; /** The elements' transforms, for `applyCSSTransforms` once the layers are laid out. */ transforms: CSSTransforms; /** * Inline SVG elements by the frame built for each. The frame takes the element's box and * style but none of its shapes, which the caller draws into it at the size layout gives it. */ svgs: Map; /** Containers whose children paint in `z-index` order, for `applyStacking` once laid out. */ stackings: Stackings; /** Background pictures to place once laid out, by `placeBackgroundPictures`. */ backgroundPictures: BackgroundPicture[]; } /** * The layers a styled document describes. Where its layout was recorded, top-level layers sit * at their captured boxes, and `boxes` lets the caller check auto layout against the rest once * it has laid the layers out. */ declare function designDocumentToLayers(document: DesignDocument, options?: DesignDocumentToSceneGraphOptions): DesignLayers; declare function designDocumentToSceneGraph(document: DesignDocument, options?: DesignDocumentToSceneGraphOptions): SceneGraph; //#endregion export { BackgroundPicture, CSSTransform, CSSTransforms, CapturedBox, CapturedBoxes, DesignDocumentToSceneGraphOptions, DesignLayers, ElementSVG, ImagePicture, Stacking, Stackings, applyCSSTransforms, applyStacking, designDocumentToLayers, designDocumentToSceneGraph, elementSVG, imagePicture, placeBackgroundPictures, placeLayersFromLayout }; //# sourceMappingURL=scene-graph.d.ts.map