nehan
Version:
Html layout engine for paged-media written in Typescript
121 lines • 3.79 kB
JavaScript
import { LogicalMargin, LogicalBoxEdge, LogicalEdgeDirections, } from './public-api';
export class ContextEdgeState {
constructor() {
this.state = { before: false, end: false, after: false, start: false };
}
mask(edge) {
LogicalEdgeDirections.forEach(dir => {
edge[dir] = this.state[dir] ? edge[dir] : 0;
});
}
clear() {
this.state.before = false;
this.state.end = false;
this.state.after = false;
this.state.start = false;
}
clearBlock() {
this.state.before = false;
this.state.after = false;
}
addEdge(direction) {
this.state[direction] = true;
}
isEnable(direction) {
return this.state[direction];
}
}
export class ContextEdgeSize {
constructor(edgeSize, edgeState = new ContextEdgeState()) {
this.edgeSize = edgeSize;
this.edgeState = edgeState;
}
mask(edge) {
this.edgeState.mask(edge);
}
clear() {
this.edgeState.clear();
}
clearBlock() {
this.edgeState.clearBlock();
}
addEdge(direction) {
this.edgeState.addEdge(direction);
}
getSize(direction) {
return this.edgeState.isEnable(direction) ? this.edgeSize[direction] : 0;
}
get measure() {
return this.getSize("start") + this.getSize("end");
}
get extent() {
return this.getSize("before") + this.getSize("after");
}
}
export class ContextBoxEdge {
constructor(envEdge) {
this.envEdge = envEdge;
this.padding = new ContextEdgeSize(envEdge.padding);
this.margin = new ContextEdgeSize(envEdge.margin);
this.borderWidth = new ContextEdgeSize(envEdge.border.width);
}
clear() {
this.padding.clear();
this.margin.clear();
this.borderWidth.clear();
}
clearBlock() {
this.padding.clearBlock();
this.margin.clearBlock();
this.borderWidth.clearBlock();
}
get currentBorder() {
const border = this.envEdge.border.clone();
this.borderWidth.mask(border.width);
return border;
}
get currentPadding() {
const padding = this.envEdge.padding.clone();
this.padding.mask(padding);
return padding;
}
get currentMargin() {
const margin = this.envEdge.margin.clone();
this.margin.mask(margin);
return margin;
}
get currentBorderBoxEdge() {
const border = this.currentBorder;
const padding = this.currentPadding;
const margin = LogicalMargin.none;
return new LogicalBoxEdge({ padding, border, margin });
}
get currentMarginBoxEdge() {
const border = this.currentBorder;
const padding = this.currentPadding;
const margin = this.currentMargin;
return new LogicalBoxEdge({ padding, border, margin });
}
getBorderBoxEdgeSize(direction) {
return this.borderWidth.getSize(direction) + this.padding.getSize(direction);
}
getMarginBoxEdgeSize(direction) {
return this.borderWidth.getSize(direction) + this.padding.getSize(direction) + this.margin.getSize(direction);
}
get borderBoxAfterSize() {
return this.borderWidth.getSize("after") + this.padding.getSize("after");
}
get borderBoxStartSize() {
return this.borderWidth.getSize("start") + this.padding.getSize("start");
}
get borderBoxBeforeSize() {
return this.borderWidth.getSize("before") + this.padding.getSize("before");
}
get borderBoxMeasure() {
return this.borderWidth.measure + this.padding.measure;
}
get borderBoxExtent() {
return this.borderWidth.extent + this.padding.extent;
}
}
//# sourceMappingURL=context-edge.js.map