impress.me
Version:
Create impress.js presentations from markdown documents with style
57 lines (56 loc) • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinearPositionStrategy = exports.overviewPosition = void 0;
const helpers_1 = require("../helpers");
exports.overviewPosition = (node, config, nodeWidth, scale) => {
const root = helpers_1.findRoot(node);
const nodes = helpers_1.flattenNodes(root);
// const minX = -(config.width / 2) - 16;
// const minY = -(config.height / 2) - 16;
const minX = nodes.map(n => n.pos ? n.pos.x + (nodeWidth / 2 * scale) : 0)
.reduce((min, curr) => Math.min(min, curr), -(config.width / 2)) - 16;
const minY = nodes.map(n => n.pos ? n.pos.y + (nodeWidth / 2 * scale) : 0)
.reduce((min, curr) => Math.min(min, curr), -(config.height / 2)) - 16;
const maxX = nodes.map(n => n.pos ? n.pos.x + (nodeWidth / 2 * scale) : 0)
.reduce((max, curr) => Math.max(max, curr), config.width / 2) + 16;
const maxY = nodes.map(n => n.pos ? n.pos.y + (nodeWidth / 2 * scale) : 0)
.reduce((max, curr) => Math.max(max, curr), config.height / 2) + 16;
const totalWidth = maxX - minX;
const totalHeight = maxY - minY;
return {
x: (minX + maxX) / 2,
y: (minY + maxY) / 2,
z: 0,
// we want to show a bit more than just all of the steps
scale: Math.max(totalWidth / config.width, totalHeight / config.height),
};
};
class LinearPositionStrategy {
constructor(config) {
this.config = config;
this.width = 1080;
this.scale = 0.4;
this.offset = {
x: -this.config.width * 0.5,
y: 100,
z: 0,
scale: this.scale,
};
}
calculate(node) {
if (node.classes && node.classes.includes('overview')) {
return exports.overviewPosition(node, this.config, this.width, this.scale);
}
if (node.depth === 1) {
return {
x: 0,
y: 0,
z: 0,
scale: 1,
};
}
const step = helpers_1.findIndex(helpers_1.findRoot(node), node);
return Object.assign(Object.assign({}, this.offset), { x: this.offset.x + (step * this.config.width * this.offset.scale) });
}
}
exports.LinearPositionStrategy = LinearPositionStrategy;