UNPKG

nehan

Version:

Html layout engine for paged-media written in Typescript

88 lines 2.75 kB
import { Utils, LogicalEdgeMap, CssCascade, } from "./public-api"; export const LogicalEdgeDirections = ["before", "end", "after", "start"]; export const PhysicalEdgeDirections = ["top", "right", "bottom", "left"]; export class PhysicalEdge { constructor(values) { this.top = values.top; this.right = values.right; this.bottom = values.bottom; this.left = values.left; } get items() { return [ { prop: "top", value: this.top }, { prop: "right", value: this.right }, { prop: "bottom", value: this.bottom }, { prop: "left", value: this.left } ]; } } export class LogicalEdge { constructor(values) { this.before = values.before; this.end = values.end; this.after = values.after; this.start = values.start; } static isBlockEdge(direction) { return (direction === "before" || direction === "after"); } static isInlineEdge(direction) { return (direction === "start" || direction === "end"); } getPhysicalEdgeValue(writingMode) { return this.items.reduce((value, item) => { const physicalProp = LogicalEdgeMap.select(writingMode).get(item.prop); value[physicalProp] = item.value; return value; }, {}); } getPhysicalEdge(writing_mode) { return new PhysicalEdge(this.getPhysicalEdgeValue(writing_mode)); } getPropByLogicalDirection(direction) { throw new Error("LogicalEdge<T>::getPropByLogicalDirection must be overrided."); } get values() { return { before: this.before, end: this.end, after: this.after, start: this.start }; } get items() { return [ { prop: "before", value: this.before }, { prop: "end", value: this.end }, { prop: "after", value: this.after }, { prop: "start", value: this.start } ]; } } export class LogicalEdgeSize extends LogicalEdge { static loadDirection(element, prop) { return Utils.atoi(CssCascade.getValue(element, prop)); } static get zeroValue() { return { before: 0, end: 0, after: 0, start: 0 }; } isZero() { return this.before === 0 && this.end === 0 && this.after === 0 && this.start === 0; } clone() { return new LogicalEdgeSize({ before: this.before, end: this.end, after: this.after, start: this.start }); } get extent() { return this.before + this.after; } get measure() { return this.start + this.end; } } //# sourceMappingURL=logical-edge.js.map