UNPKG

react-native-skia-responsive-text

Version:

A library providing a wrapper for the React Native Skia Text component, offering features like user-friendly text alignment, efficient multiline text management, and straightforward text truncation.

43 lines (42 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeLines = exports.getTextChunks = void 0; const isSpace = text => text.trim().length === 0; const getTextChunks = text => { const splittedText = text.split(/(\s+)/g).filter(Boolean); const chunks = []; if (splittedText.length === 0) { return chunks; } const firstChunk = splittedText[0]; let prefix = ''; let i = 0; if (isSpace(firstChunk)) { prefix = firstChunk; i++; } for (; i < splittedText.length; i++) { const chunk = prefix + splittedText[i]; prefix = ''; const nextChunk = splittedText[i + 1]; if (nextChunk && isSpace(nextChunk)) { chunks.push(chunk + nextChunk); i++; } else { chunks.push(chunk); } } return chunks; }; exports.getTextChunks = getTextChunks; const mergeLines = lines => lines.reduce((acc, line) => ({ text: acc.text + line.text, width: acc.width + line.width }), { text: '', width: 0 }); exports.mergeLines = mergeLines; //# sourceMappingURL=text.js.map