@react-pdf/textkit
Advanced tools
Comparing version 0.3.4 to 0.3.5
@@ -33,3 +33,4 @@ "use strict"; | ||
var _default = append; | ||
var _default = R.curryN(2, append); | ||
exports["default"] = _default; |
@@ -35,3 +35,4 @@ "use strict"; | ||
var _default = prepend; | ||
var _default = R.curryN(2, prepend); | ||
exports["default"] = _default; |
@@ -40,7 +40,5 @@ "use strict"; | ||
marginRight: a.marginRight || a.margin || 0, | ||
maxLines: a.maxLines || Infinity, | ||
opacity: R.isNil(a.opacity) ? 1 : a.opacity, | ||
paddingTop: a.paddingTop || a.padding || 0, | ||
paragraphSpacing: a.paragraphSpacing || 0, | ||
truncationMode: a.truncationMode || (a.truncate ? 'right' : null), | ||
underline: a.underline || false, | ||
@@ -47,0 +45,0 @@ underlineColor: a.underlineColor || a.color || 'black', |
@@ -16,47 +16,12 @@ "use strict"; | ||
var _layoutParagraph = _interopRequireDefault(require("./layoutParagraph")); | ||
var _slice = _interopRequireDefault(require("../block/slice")); | ||
/** | ||
* Get paragrpah block height | ||
* | ||
* @param {Object} paragraph block | ||
* @return {number} paragraph block height | ||
*/ | ||
var blockHeight = R.compose(R.sum, R.map(R.prop('height')), R.pluck('box')); | ||
/** | ||
* Slice block at given height | ||
* | ||
* @param {number} height | ||
* @param {Object} paragraph block | ||
* @return {number} sliced paragraph block | ||
*/ | ||
var _height = _interopRequireDefault(require("../block/height")); | ||
var sliceBlockAtHeight = function sliceBlockAtHeight(height, block) { | ||
var newBlock = []; | ||
var counter = 0; | ||
var _truncate = _interopRequireDefault(require("../block/truncate")); | ||
for (var _iterator = block, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _layoutParagraph = _interopRequireDefault(require("./layoutParagraph")); | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var _sliceAtHeight = _interopRequireDefault(require("../block/sliceAtHeight")); | ||
var line = _ref; | ||
counter += line.box.height; | ||
if (counter < height) { | ||
newBlock.push(line); | ||
} else { | ||
break; | ||
} | ||
} | ||
return newBlock; | ||
}; | ||
/** | ||
@@ -72,20 +37,24 @@ * Layout paragraphs inside container until it does not | ||
*/ | ||
var typesetter = function typesetter(engines, options, container, attributedStrings) { | ||
var blocks = []; | ||
var paragraphs = [].concat(attributedStrings); | ||
var maxLines = R.propOr(Infinity, 'maxLines', container); | ||
var truncateEllipsis = container.truncateMode === 'ellipsis'; | ||
var linesCount = maxLines; | ||
var paragraphRect = (0, _copy["default"])(container); | ||
var nextParagraph = paragraphs.shift(); | ||
while (nextParagraph) { | ||
while (linesCount > 0 && nextParagraph) { | ||
var block = (0, _layoutParagraph["default"])(engines, options)(paragraphRect, nextParagraph); | ||
var linesHeight = blockHeight(block); | ||
var slicedBlock = (0, _slice["default"])(linesCount, block); | ||
var linesHeight = (0, _height["default"])(slicedBlock); | ||
var shouldTruncate = truncateEllipsis && block.length !== slicedBlock.length; | ||
linesCount -= slicedBlock.length; | ||
if (paragraphRect.height >= linesHeight) { | ||
blocks.push(block); | ||
blocks.push(R.when(R.always(shouldTruncate), _truncate["default"])(slicedBlock)); | ||
paragraphRect = (0, _crop["default"])(linesHeight, paragraphRect); | ||
nextParagraph = paragraphs.shift(); | ||
} else { | ||
blocks.push(sliceBlockAtHeight(paragraphRect.height, block)); | ||
blocks.push(R.compose(_truncate["default"], (0, _sliceAtHeight["default"])(paragraphRect.height))(slicedBlock)); | ||
break; | ||
@@ -92,0 +61,0 @@ } |
{ | ||
"name": "@react-pdf/textkit", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "An advanced text layout framework", | ||
"main": "./index.js", | ||
"scripts": { | ||
"prebuild": "rimraf attributedString layout engines glyph indices rect renderers run utils index.js", | ||
"prebuild": "rimraf attributedString layout engines glyph indices rect renderers run utils block index.js", | ||
"prepublish": "npm run build", | ||
@@ -23,2 +23,3 @@ "build": "babel ./src --out-dir ./", | ||
"run", | ||
"block", | ||
"utils", | ||
@@ -25,0 +26,0 @@ "index.js" |
179615
140
4890