impress.me
Version:
Create impress.js presentations from markdown documents with style
52 lines (51 loc) • 2.16 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RowPositionStrategy = void 0;
const helpers_1 = require("../helpers");
const shape_1 = require("../shape");
const linear_position_strategy_1 = require("./linear-position.strategy");
class RowPositionStrategy {
constructor(config) {
this.config = config;
this.scale = 0.4;
this.shape = shape_1.shapeConfig[this.config.shape];
this.offset = {
x: -(this.config.width * this.scale / 2),
y: (this.shape.height + this.shape.parentOffset.y - 1080) * 0.2,
z: 0,
scale: this.scale,
};
}
calculate(node) {
if (node.classes && node.classes.includes('overview')) {
return linear_position_strategy_1.overviewPosition(node, this.config, this.shape.width, this.scale);
}
let siblingIndex;
let siblings;
let previousSibling;
switch (node.depth) {
case 1:
return {
x: 0,
y: 0,
z: 0,
scale: 1,
};
case 2: {
siblingIndex = node.parent.children.indexOf(node);
if (siblingIndex === 0) {
// first h2 step
return Object.assign(Object.assign({}, this.offset), { y: this.offset.y + (siblingIndex * this.shape.height * this.offset.scale) });
}
siblings = node.parent.children;
previousSibling = siblings[siblingIndex - 1];
return Object.assign(Object.assign({}, this.offset), { y: previousSibling.pos.y + ((this.shape.height + this.shape.siblingOffset.y) * this.offset.scale) });
}
default: {
siblingIndex = helpers_1.findIndex(node.parent, node);
return Object.assign(Object.assign({}, this.offset), { x: this.offset.x + (siblingIndex * (this.shape.width + this.shape.siblingOffset.x) * this.offset.scale), y: node.parent.pos.y });
}
}
}
}
exports.RowPositionStrategy = RowPositionStrategy;