react-cursive-handwrite
Version:
React component to animate cursive handwriting text
36 lines (35 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.assembleText = assembleText;
const PathCreator_1 = require("./PathCreator");
function assembleText(text, letterPaths) {
console.log(`Assembling text: "${text}" with ${Object.keys(letterPaths).length} available letters`);
let maxHeight = 0;
let totalWidth = 0;
let totalLength = 0;
const paths = [];
for (let i = 0; i < text.length; i++) {
const letter = text[i].toLowerCase();
console.log(`Processing letter "${letter}" at position ${i}`);
if (letter === ' ') {
continue;
}
const letterData = letterPaths[letter];
if (!letterData) {
console.log(`Missing letter: "${letter}"`);
continue;
}
// Create path with no offset to stack them
const positionedPath = (0, PathCreator_1.createPositionedPath)(letterData, 0);
paths.push(positionedPath);
maxHeight = Math.max(maxHeight, letterData.height);
totalWidth = Math.max(totalWidth, letterData.width);
totalLength += (0, PathCreator_1.measurePath)(positionedPath.path).length;
}
return {
paths,
totalWidth,
maxHeight,
totalLength
};
}