nehan
Version:
Html layout engine for paged-media written in Typescript
64 lines • 1.94 kB
JavaScript
import { Config, LogicalBlockNode, } from './public-api';
export class LayoutResult {
constructor(type, body) {
this.type = type;
this.body = body;
}
static skip(ctx, msg = "") {
if (Config.debugLayout) {
console.log("created skip(%s):", msg, ctx);
}
return new LayoutResult('skip', ctx);
}
static lineBreak(ctx, msg = "") {
if (Config.debugLayout) {
console.log("created line-break(%s):", msg, ctx);
}
return new LayoutResult('line-break', ctx);
}
static iblockInlineBreak(ctx, msg = "") {
if (Config.debugLayout) {
console.log("created iblock-inline-break(%s):", msg, ctx);
}
return new LayoutResult('iblock-inline-break', ctx);
}
static pageBreak(ctx, msg = "") {
if (Config.debugLayout) {
console.log("created page break(%s):", msg, ctx);
}
return new LayoutResult('page-break', ctx);
}
static logicalNode(type, node) {
return new LayoutResult(type, node);
}
isFloatable() {
switch (this.type) {
case 'block':
case 'inline-block':
case 're-block':
return true;
}
return false;
}
isBlockLevel() {
switch (this.type) {
case 'block':
case 'block-link':
case 're-block':
case 'table':
case 'table-cells':
case 'table-row-group':
case 'table-row':
return true;
}
return false;
}
getBodyAsBlockNode() {
if (this.body && this.body instanceof LogicalBlockNode) {
return this.body;
}
console.log("Type error: body is not LogicalBlockNode. %o", this);
throw new Error("Type error: body is not LogicalBlockNode");
}
}
//# sourceMappingURL=layout-result.js.map