New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@react-pdf/textkit

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-pdf/textkit - npm Package Compare versions

Comparing version

to
3.0.0

lib/positions/advanceWidth.js

22

CHANGELOG.md
# @react-pdf/textkit
## 2.1.0
### Minor Changes
## 3.0.0
### Major Changes
- [#1830](https://github.com/diegomura/react-pdf/pull/1830) [`9a2b935`](https://github.com/diegomura/react-pdf/commit/9a2b935cfe173f80425ed87d9f474da271c050d2) Thanks [@diegomura](https://github.com/diegomura)! - refactor: remove ramda from textkit package
- [#1654](https://github.com/diegomura/react-pdf/pull/1654) [`ccf3bf2`](https://github.com/diegomura/react-pdf/commit/ccf3bf22867a9bd49668cdd3543ec32492a40e4b) Thanks [@jeetiss](https://github.com/jeetiss)! - added `@babel/runtime` to dependencies
### Patch Changes
- [#1838](https://github.com/diegomura/react-pdf/pull/1838) [`9bdb5c9`](https://github.com/diegomura/react-pdf/commit/9bdb5c934a822340754cd4c892d399f91f6218de) Thanks [@diegomura](https://github.com/diegomura)! - feat: create fns package
### Patch Changes
- Updated dependencies [[`434df31`](https://github.com/diegomura/react-pdf/commit/434df317a92ae5b51ee7b23a9f6500de0b6aa4aa), [`9bdb5c9`](https://github.com/diegomura/react-pdf/commit/9bdb5c934a822340754cd4c892d399f91f6218de)]:
- @react-pdf/unicode-properties@2.6.0
- @react-pdf/fns@1.0.0
## 2.1.0
### Minor Changes
- [#1581](https://github.com/diegomura/react-pdf/pull/1581) [`04449ab`](https://github.com/diegomura/react-pdf/commit/04449ab352db0cca2155024dd3e8c690e42193ca) Thanks [@jeetiss](https://github.com/jeetiss)! - added changelog with changesets
- [#1654](https://github.com/diegomura/react-pdf/pull/1654) [`ccf3bf2`](https://github.com/diegomura/react-pdf/commit/ccf3bf22867a9bd49668cdd3543ec32492a40e4b) Thanks [@jeetiss](https://github.com/jeetiss)! - added `@babel/runtime` to dependencies
### Patch Changes
- [#1581](https://github.com/diegomura/react-pdf/pull/1581) [`04449ab`](https://github.com/diegomura/react-pdf/commit/04449ab352db0cca2155024dd3e8c690e42193ca) Thanks [@jeetiss](https://github.com/jeetiss)! - added changelog with changesets
- [#1567](https://github.com/diegomura/react-pdf/pull/1567) [`5d2d688`](https://github.com/diegomura/react-pdf/commit/5d2d688e18c830bb96c6e08446437d29f9f9c65f) Thanks [@hayoung0Lee](https://github.com/hayoung0Lee)! - fixed line breaks for the case when the word in a text is bigger than the given width
* [#1567](https://github.com/diegomura/react-pdf/pull/1567) [`5d2d688`](https://github.com/diegomura/react-pdf/commit/5d2d688e18c830bb96c6e08446437d29f9f9c65f) Thanks [@hayoung0Lee](https://github.com/hayoung0Lee)! - fixed line breaks for the case when the word in a text is bigger than the given width
- Updated dependencies [[`4c5d527`](https://github.com/diegomura/react-pdf/commit/4c5d52721d29d843f1d09c3fd74370832429f70e), [`04449ab`](https://github.com/diegomura/react-pdf/commit/04449ab352db0cca2155024dd3e8c690e42193ca)]:
* Updated dependencies [[`4c5d527`](https://github.com/diegomura/react-pdf/commit/4c5d52721d29d843f1d09c3fd74370832429f70e), [`04449ab`](https://github.com/diegomura/react-pdf/commit/04449ab352db0cca2155024dd3e8c690e42193ca)]:
- @react-pdf/unicode-properties@2.5.0

@@ -5,11 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _reduce = _interopRequireDefault(require("./reduce"));
var _advanceWidth = _interopRequireDefault(require("../run/advanceWidth"));

@@ -23,4 +17,11 @@

*/
var advanceWidth = (0, _reduce.default)(R.add, _advanceWidth.default);
var advanceWidth = function advanceWidth(attributeString) {
var reducer = function reducer(acc, run) {
return acc + (0, _advanceWidth.default)(run);
};
return attributeString.runs.reduce(reducer, 0);
};
var _default = advanceWidth;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _filter = _interopRequireDefault(require("../run/filter"));

@@ -27,8 +23,10 @@

*/
var advanceWidthBetween = function advanceWidthBetween(start, end, string) {
return R.compose(R.sum, R.map((0, _advanceWidthBetween.default)(start, end)), (0, _filter.default)(start, end), R.propOr([], 'runs'))(string);
var advanceWidthBetween = function advanceWidthBetween(start, end, attributedString) {
var runs = (0, _filter.default)(start, end, attributedString.runs);
return runs.reduce(function (acc, run) {
return acc + (0, _advanceWidthBetween.default)(start, end, run);
}, 0);
};
var _default = R.curryN(3, advanceWidthBetween);
var _default = advanceWidthBetween;
exports.default = _default;

@@ -5,8 +5,6 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -26,12 +24,16 @@ var _empty = _interopRequireDefault(require("../run/empty"));

*/
var append = function append(glyph, string) {
var codePoints = R.propOr([], 'codePoints')(glyph);
return R.evolve({
string: R.concat(R.__, (0, _stringFromCodePoints.default)(codePoints)),
runs: R.converge(R.concat, [R.init, R.compose(R.unapply(R.identity), (0, _append.default)(glyph), R.either(R.last, _empty.default))])
})(string);
var append = function append(glyph, attributedString) {
var codePoints = (glyph === null || glyph === void 0 ? void 0 : glyph.codePoints) || [];
var codePointsString = (0, _stringFromCodePoints.default)(codePoints);
var string = attributedString.string + codePointsString;
var firstRuns = attributedString.runs.slice(0, -1);
var lastRun = (0, _fns.last)(attributedString.runs) || (0, _empty.default)();
var runs = firstRuns.concat((0, _append.default)(glyph, lastRun));
return Object.assign({}, attributedString, {
string: string,
runs: runs
});
};
var _default = R.curryN(2, append);
var _default = append;
exports.default = _default;

@@ -5,11 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _reduce = _interopRequireDefault(require("./reduce"));
var _ascent = _interopRequireDefault(require("../run/ascent"));

@@ -23,4 +17,11 @@

*/
var ascent = (0, _reduce.default)(R.max, _ascent.default);
var ascent = function ascent(attributeString) {
var reducer = function reducer(acc, run) {
return Math.max(acc, (0, _ascent.default)(run));
};
return attributeString.runs.reduce(reducer, 0);
};
var _default = ascent;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _copy = _interopRequireDefault(require("../run/copy"));

@@ -21,8 +17,10 @@

*/
var copy = R.evolve({
string: R.identity,
syllables: R.identity,
runs: R.map(_copy.default)
});
var copy = function copy(attributeString) {
var runs = attributeString.runs.map(_copy.default);
return Object.assign({}, attributeString, {
runs: runs
});
};
var _default = copy;
exports.default = _default;

@@ -5,11 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _reduce = _interopRequireDefault(require("./reduce"));
var _descent = _interopRequireDefault(require("../run/descent"));

@@ -23,4 +17,11 @@

*/
var descent = (0, _reduce.default)(R.min, _descent.default);
var descent = function descent(attributeString) {
var reducer = function reducer(acc, run) {
return Math.min(acc, (0, _descent.default)(run));
};
return attributeString.runs.reduce(reducer, 0);
};
var _default = descent;
exports.default = _default;

@@ -5,8 +5,6 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -21,7 +19,9 @@ var _dropLast = _interopRequireDefault(require("../run/dropLast"));

*/
var dropLast = function dropLast(string) {
return R.evolve({
string: R.dropLast(1),
runs: R.adjust(-1, _dropLast.default)
})(string);
var dropLast = function dropLast(attributeString) {
var string = (0, _fns.dropLast)(attributeString.string);
var runs = (0, _fns.adjust)(-1, _dropLast.default, attributeString.runs);
return Object.assign({}, attributeString, {
string: string,
runs: runs
});
};

@@ -28,0 +28,0 @@

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -15,7 +11,10 @@ * Returns empty attributed string

*/
var empty = R.always({
string: '',
runs: []
});
var empty = function empty() {
return {
string: '',
runs: []
};
};
var _default = empty;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -13,7 +11,11 @@ /**

*
* @param {Object} glyph string
* @param {Object} attributed string
* @return {number} end
*/
var end = R.ifElse(R.pathEq(['runs', 'length'], 0), R.always(0), R.compose(R.prop('end'), R.last, R.prop('runs')));
var end = function end(attributedString) {
var runs = attributedString.runs;
return runs.length === 0 ? 0 : (0, _fns.last)(runs).end;
};
var _default = end;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -18,15 +14,17 @@ * Create attributed string from text fragments

var offset = 0;
var getRuns = R.map(function (fragment) {
var run = {
var string = '';
var runs = [];
fragments.forEach(function (fragment) {
string += fragment.string;
runs.push({
start: offset,
end: offset + fragment.string.length,
attributes: fragment.attributes || {}
};
});
offset += fragment.string.length;
return run;
});
return R.applySpec({
runs: getRuns,
string: R.o(R.join(''), R.pluck('string'))
})(fragments);
return {
string: string,
runs: runs
};
};

@@ -33,0 +31,0 @@

@@ -5,11 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _reduce = _interopRequireDefault(require("./reduce"));
var _height = _interopRequireDefault(require("../run/height"));

@@ -23,4 +17,11 @@

*/
var height = (0, _reduce.default)(R.max, _height.default);
var height = function height(attributeString) {
var reducer = function reducer(acc, run) {
return Math.max(acc, (0, _height.default)(run));
};
return attributeString.runs.reduce(reducer, 0);
};
var _default = height;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _length = _interopRequireDefault(require("../run/length"));

@@ -29,3 +25,3 @@

var counter = 0;
var runs = R.propOr([], 'runs', string);
var runs = string.runs || [];

@@ -47,4 +43,3 @@ for (var i = 0; i < runs.length; i += 1) {

var _default = R.curryN(2, indexAtOffset);
var _default = indexAtOffset;
exports.default = _default;

@@ -5,12 +5,8 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _append = _interopRequireDefault(require("./append"));
var _copy = _interopRequireDefault(require("../run/copy"));
var _add = _interopRequireDefault(require("../run/add"));

@@ -23,13 +19,2 @@ var _insert = _interopRequireDefault(require("../run/insert"));

var mapCond = function mapCond(conds) {
return R.addIndex(R.map)(R.cond(conds));
};
var idxEquals = function idxEquals(idx) {
return R.compose(R.equals(idx), R.nthArg(1));
};
var idxGt = function idxGt(idx) {
return R.compose(R.gt(R.__, idx), R.nthArg(1));
};
/**

@@ -43,26 +28,20 @@ * Insert glyph into attributed string

*/
var insertGlyph = function insertGlyph(index, glyph, attributedString) {
var runIndex = (0, _runIndexAt.default)(index, attributedString); // Add glyph to the end if run index invalid
var insertGlyph = function insertGlyph(index, glyph, string) {
var runIndex = (0, _runIndexAt.default)(index, string); // Add glyph to the end if run index invalid
if (runIndex === -1) {
return (0, _append.default)(glyph, string);
}
var codePoints = R.propOr([], 'codePoints')(glyph);
var incRange = R.add(R.length(codePoints));
return R.evolve({
string: R.compose(R.join(''), R.insert(index, (0, _stringFromCodePoints.default)(codePoints))),
runs: mapCond([[idxEquals(runIndex), function (run) {
return (0, _insert.default)(index - run.start, glyph, run);
}], [idxGt(runIndex), R.evolve({
start: incRange,
end: incRange
})], [R.T, _copy.default]])
})(string);
if (runIndex === -1) return (0, _append.default)(glyph, attributedString);
var codePoints = (glyph === null || glyph === void 0 ? void 0 : glyph.codePoints) || [];
var string = attributedString.string.slice(0, index) + (0, _stringFromCodePoints.default)(codePoints) + attributedString.string.slice(index);
var runs = attributedString.runs.map(function (run, i) {
if (i === runIndex) return (0, _insert.default)(index - run.start, glyph, run);
if (i > runIndex) return (0, _add.default)(codePoints.length, run);
return run;
});
return Object.assign({}, attributedString, {
string: string,
runs: runs
});
};
var _default = R.curryN(3, insertGlyph);
var _default = insertGlyph;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _leadingOffset = _interopRequireDefault(require("../run/leadingOffset"));

@@ -21,4 +17,8 @@

*/
var leadingOffset = R.compose(_leadingOffset.default, R.head, R.propOr([], 'runs'));
var leadingOffset = function leadingOffset(attributedString) {
var runs = attributedString.runs || [];
return (0, _leadingOffset.default)(runs[0]);
};
var _default = leadingOffset;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _start = _interopRequireDefault(require("./start"));

@@ -23,4 +19,7 @@

*/
var length = R.converge(R.subtract, [_end.default, _start.default]);
var length = function length(attributedString) {
return (0, _end.default)(attributedString) - (0, _start.default)(attributedString);
};
var _default = length;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _add = _interopRequireDefault(require("../run/add"));

@@ -28,12 +24,18 @@

*/
var prepend = function prepend(glyph, string) {
var codePoints = R.propOr([], 'codePoints')(glyph);
return R.evolve({
string: R.concat((0, _stringFromCodePoints.default)(codePoints)),
runs: R.converge(R.concat, [R.compose(R.unapply(R.identity), (0, _prepend.default)(glyph), R.either(R.head, _empty.default)), R.compose(R.map((0, _add.default)(codePoints.length)), R.tail)])
})(string);
var prepend = function prepend(glyph, attributedString) {
var codePoints = (glyph === null || glyph === void 0 ? void 0 : glyph.codePoints) || [];
var string = (0, _stringFromCodePoints.default)(codePoints) + attributedString.string;
var offset = codePoints.length;
var firstRun = attributedString.runs[0] || (0, _empty.default)();
var lastRuns = attributedString.runs.slice(1).map(function (run) {
return (0, _add.default)(offset, run);
});
var runs = [(0, _prepend.default)(glyph, firstRun)].concat(lastRuns);
return Object.assign({}, attributedString, {
runs: runs,
string: string
});
};
var _default = R.curryN(2, prepend);
var _default = prepend;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _runIndexAt = _interopRequireDefault(require("./runIndexAt"));

@@ -23,8 +19,7 @@

var runAt = function runAt(n, attributedString) {
var runIndex = (0, _runIndexAt.default)(n)(attributedString);
return R.path(['runs', runIndex])(attributedString);
var runIndex = (0, _runIndexAt.default)(n, attributedString);
return attributedString.runs[runIndex];
};
var _default = R.curryN(2, runAt);
var _default = runAt;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _runIndexAt = _interopRequireDefault(require("../run/runIndexAt"));

@@ -23,7 +19,6 @@

var runIndexAt = function runIndexAt(n, string) {
return R.compose((0, _runIndexAt.default)(n), R.prop('runs'))(string);
return (0, _runIndexAt.default)(n, string.runs);
};
var _default = R.curryN(2, runIndexAt);
var _default = runIndexAt;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _slice = _interopRequireDefault(require("../run/slice"));

@@ -19,4 +15,2 @@

var _mapIndexed = _interopRequireDefault(require("../utils/mapIndexed"));
/**

@@ -30,19 +24,19 @@ * Slice array of runs

*/
var sliceRuns = function sliceRuns(start, end) {
return function (runs) {
var firstRun = function firstRun(a) {
return (0, _slice.default)(start - a.start, end - a.start, a);
};
var sliceRuns = function sliceRuns(start, end, runs) {
var sliceFirstRun = function sliceFirstRun(a) {
return (0, _slice.default)(start - a.start, end - a.start, a);
};
var lastRun = function lastRun(a) {
return (0, _slice.default)(0, end - a.start, a);
};
var sliceLastRun = function sliceLastRun(a) {
return (0, _slice.default)(0, end - a.start, a);
};
var intermediateRun = R.identity;
var res = (0, _mapIndexed.default)([R.o((0, _subtract.default)(start), firstRun), // Slice first run
R.o((0, _subtract.default)(start), intermediateRun), // Slice intermediate runs
R.o((0, _subtract.default)(start), lastRun) // Slice last run
])(runs);
return res;
};
return runs.map(function (run, i) {
var result = run;
var isFirst = i === 0;
var isLast = !isFirst && i === runs.length - 1;
if (isFirst) result = sliceFirstRun(run);
if (isLast) result = sliceLastRun(run);
return (0, _subtract.default)(start, result);
});
};

@@ -59,11 +53,14 @@ /**

var slice = function slice(start, end, string) {
return R.ifElse(R.pathEq(['string', 'length'], 0), R.identity, R.evolve({
string: R.slice(start, end),
runs: R.compose(sliceRuns(start, end), (0, _filter.default)(start, end))
}))(string);
var slice = function slice(start, end, attributedString) {
if (attributedString.string.length === 0) return attributedString;
var string = attributedString.string.slice(start, end);
var filteredRuns = (0, _filter.default)(start, end, attributedString.runs);
var slicedRuns = sliceRuns(start, end, filteredRuns);
return Object.assign({}, attributedString, {
string: string,
runs: slicedRuns
});
};
var _default = R.curryN(3, slice);
var _default = slice;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _slice = _interopRequireDefault(require("./slice"));

@@ -29,4 +25,3 @@

var _default = R.curryN(2, sliceAtOffset);
var _default = sliceAtOffset;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**
* Get attributed string start value
*
* @param {Object} glyph string
* @param {Object} attributed string
* @return {number} start
*/
var start = R.ifElse(R.pathEq(['runs', 'length'], 0), R.always(0), R.path(['runs', 0, 'start']));
var start = function start(attributedString) {
var runs = attributedString.runs;
return runs.length === 0 ? 0 : runs[0].start;
};
var _default = start;
exports.default = _default;

@@ -5,8 +5,6 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -21,4 +19,8 @@ var _trailingOffset = _interopRequireDefault(require("../run/trailingOffset"));

*/
var trailingOffset = R.compose(_trailingOffset.default, R.last, R.propOr([], 'runs'));
var trailingOffset = function trailingOffset(attributedString) {
var runs = attributedString.runs || [];
return (0, _trailingOffset.default)((0, _fns.last)(runs));
};
var _default = trailingOffset;
exports.default = _default;

@@ -5,14 +5,15 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _slice = _interopRequireDefault(require("./slice"));
var testChar = R.test(/\S/g);
var findCharIndex = R.findIndex(testChar);
var findLastCharIndex = R.o(R.inc, R.findLastIndex(testChar));
var findCharIndex = function findCharIndex(string) {
return string.search(/\S/g);
};
var findLastCharIndex = function findLastCharIndex(string) {
var match = string.match(/\S/g);
return match ? string.lastIndexOf(match[match.length - 1]) : -1;
};
/**

@@ -25,4 +26,10 @@ * Removes (strips) whitespace from both ends of the attributted string.

var trim = R.chain(R.apply(_slice.default), R.compose(R.juxt([findCharIndex, findLastCharIndex]), R.prop('string')));
var trim = function trim(attributedString) {
var start = findCharIndex(attributedString.string);
var end = findLastCharIndex(attributedString.string);
return (0, _slice.default)(start, end + 1, attributedString);
};
var _default = trim;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**
* Get paragrpah block height
* Get paragraph block height
*

@@ -16,4 +12,9 @@ * @param {Object} paragraph block

*/
var height = R.compose(R.sum, R.map(R.prop('height')), R.pluck('box'));
var height = function height(paragraph) {
return paragraph.reduce(function (acc, block) {
return acc + block.box.height;
}, 0);
};
var _default = height;
exports.default = _default;

@@ -13,20 +13,18 @@ "use strict";

*/
var sliceAtHeight = function sliceAtHeight(height) {
return function (block) {
var newBlock = [];
var counter = 0;
var sliceAtHeight = function sliceAtHeight(height, block) {
var newBlock = [];
var counter = 0;
for (var i = 0; i < block.length; i += 1) {
var line = block[i];
counter += line.box.height;
for (var i = 0; i < block.length; i += 1) {
var line = block[i];
counter += line.box.height;
if (counter < height) {
newBlock.push(line);
} else {
break;
}
if (counter < height) {
newBlock.push(line);
} else {
break;
}
}
return newBlock;
};
return newBlock;
};

@@ -33,0 +31,0 @@

@@ -5,13 +5,11 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");
var _trim = _interopRequireDefault(require("../attributedString/trim"));
var _append = _interopRequireDefault(require("../attributedString/append"));
var _trim = _interopRequireDefault(require("../attributedString/trim"));
var ELLIPSIS_UNICODE = 8230;

@@ -44,9 +42,15 @@ var ELLIPSIS_STRING = String.fromCharCode(ELLIPSIS_UNICODE);

var truncate = function truncate(block) {
var runs = R.propOr([], 'runs', R.last(block));
var font = R.path(['attributes', 'font'], R.last(runs));
var _last, _last2, _last2$attributes;
var runs = ((_last = (0, _fns.last)(block)) === null || _last === void 0 ? void 0 : _last.runs) || [];
var font = (_last2 = (0, _fns.last)(runs)) === null || _last2 === void 0 ? void 0 : (_last2$attributes = _last2.attributes) === null || _last2$attributes === void 0 ? void 0 : _last2$attributes.font;
if (font) {
var _Object$assign;
var index = block.length - 1;
var codePoint = getEllipsisCodePoint(font);
var glyph = font.glyphForCodePoint(codePoint);
return R.adjust(-1, R.compose((0, _append.default)(glyph), _trim.default))(block);
var lastBlock = (0, _append.default)(glyph, (0, _trim.default)(block[index]));
return Object.assign([], block, (_Object$assign = {}, _Object$assign[index] = lastBlock, _Object$assign));
}

@@ -53,0 +57,0 @@

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -12,3 +10,3 @@

var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -18,3 +16,5 @@ var _empty = _interopRequireDefault(require("../../attributedString/empty"));

/* eslint-disable no-restricted-syntax */
var getFontSize = R.pathOr(12, ['attributes', 'fontSize']);
var getFontSize = function getFontSize(value) {
return value.attributes.fontSize || 12;
};
/**

@@ -29,73 +29,75 @@ * Resolve font runs in an AttributedString, grouping equal

var fontSubstitution = function fontSubstitution(options, attributedString) {
var string = attributedString.string,
runs = attributedString.runs;
var lastFont = null;
var lastIndex = 0;
var index = 0;
var res = [];
if (!string) return (0, _empty.default)();
for (var _iterator = (0, _createForOfIteratorHelperLoose2.default)(runs), _step; !(_step = _iterator()).done;) {
var run = _step.value;
var fontSubstitution = function fontSubstitution() {
return function (attributedString) {
var string = attributedString.string,
runs = attributedString.runs;
var lastFont = null;
var lastIndex = 0;
var index = 0;
var res = [];
if (!string) return (0, _empty.default)();
var _fontSize = getFontSize(run);
for (var _iterator = (0, _createForOfIteratorHelperLoose2.default)(runs), _step; !(_step = _iterator()).done;) {
var run = _step.value;
var defaultFont = run.attributes.font;
var _fontSize = getFontSize(run);
if (string.length === 0) {
res.push({
start: 0,
end: 0,
attributes: {
font: defaultFont
}
});
break;
}
var defaultFont = run.attributes.font;
for (var _iterator2 = (0, _createForOfIteratorHelperLoose2.default)(string.slice(run.start, run.end)), _step2; !(_step2 = _iterator2()).done;) {
var char = _step2.value;
var font = defaultFont;
if (string.length === 0) {
res.push({
start: 0,
end: 0,
attributes: {
font: defaultFont
}
});
break;
}
if (font !== lastFont) {
if (lastFont) {
res.push({
start: lastIndex,
end: index,
attributes: {
font: lastFont,
scale: lastFont ? _fontSize / lastFont.unitsPerEm : 0
}
});
for (var _iterator2 = (0, _createForOfIteratorHelperLoose2.default)(string.slice(run.start, run.end)), _step2; !(_step2 = _iterator2()).done;) {
var char = _step2.value;
var font = defaultFont;
if (font !== lastFont) {
if (lastFont) {
res.push({
start: lastIndex,
end: index,
attributes: {
font: lastFont,
scale: lastFont ? _fontSize / lastFont.unitsPerEm : 0
}
});
}
lastFont = font;
lastIndex = index;
}
lastFont = font;
lastIndex = index;
index += char.length;
}
}
index += char.length;
if (lastIndex < string.length) {
var fontSize = getFontSize((0, _fns.last)(runs));
res.push({
start: lastIndex,
end: string.length,
attributes: {
font: lastFont,
scale: lastFont ? fontSize / lastFont.unitsPerEm : 0
}
});
}
}
if (lastIndex < string.length) {
var fontSize = getFontSize(R.last(runs));
res.push({
start: lastIndex,
end: string.length,
attributes: {
font: lastFont,
scale: lastFont ? fontSize / lastFont.unitsPerEm : 0
}
});
}
return {
string: string,
runs: res
return {
string: string,
runs: res
};
};
};
var _default = R.curryN(2, fontSubstitution);
var _default = fontSubstitution;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _isWhiteSpace = _interopRequireDefault(require("../../glyph/isWhiteSpace"));

@@ -45,11 +41,11 @@

var getCharFactor = function getCharFactor(direction, options) {
var expandCharFactor = R.propOr({}, 'expandCharFactor', options);
var shrinkCharFactor = R.propOr({}, 'shrinkCharFactor', options);
return direction === 'GROW' ? R.merge(EXPAND_CHAR_FACTOR, expandCharFactor) : R.merge(SHRINK_CHAR_FACTOR, shrinkCharFactor);
var expandCharFactor = options.expandCharFactor || {};
var shrinkCharFactor = options.shrinkCharFactor || {};
return direction === 'GROW' ? Object.assign({}, EXPAND_CHAR_FACTOR, expandCharFactor) : Object.assign({}, SHRINK_CHAR_FACTOR, shrinkCharFactor);
};
var getWhitespaceFactor = function getWhitespaceFactor(direction, options) {
var expandWhitespaceFactor = R.propOr({}, 'expandWhitespaceFactor', options);
var shrinkWhitespaceFactor = R.propOr({}, 'shrinkWhitespaceFactor', options);
return direction === 'GROW' ? R.merge(EXPAND_WHITESPACE_FACTOR, expandWhitespaceFactor) : R.merge(SHRINK_WHITESPACE_FACTOR, shrinkWhitespaceFactor);
var expandWhitespaceFactor = options.expandWhitespaceFactor || {};
var shrinkWhitespaceFactor = options.shrinkWhitespaceFactor || {};
return direction === 'GROW' ? Object.assign({}, EXPAND_WHITESPACE_FACTOR, expandWhitespaceFactor) : Object.assign({}, SHRINK_WHITESPACE_FACTOR, shrinkWhitespaceFactor);
};

@@ -68,3 +64,3 @@

if ((0, _isWhiteSpace.default)(glyph)) {
f = R.clone(whitespaceFactor);
f = Object.assign({}, whitespaceFactor);

@@ -79,7 +75,7 @@ if (index === glyphs.length - 1) {

} else if (glyph.isMark && index > 0) {
f = R.clone(factors[index - 1]);
f = Object.assign({}, factors[index - 1]);
f.before = 0;
factors[index - 1].after = 0;
} else {
f = R.clone(charFactor);
f = Object.assign({}, charFactor);
}

@@ -97,4 +93,8 @@

var getFactor = factor(direction, options);
var concatFactors = R.useWith(R.concat, [R.identity, R.compose(getFactor, R.prop('glyphs'))]);
return R.compose(R.adjust(-1, R.assoc('after', 0)), R.adjust(0, R.assoc('before', 0)), R.reduce(concatFactors, []), R.prop('runs'))(line);
var factors = line.runs.reduce(function (acc, run) {
return acc.concat(getFactor(run.glyphs));
}, []);
factors[0].before = 0;
factors[factors.length - 1].after = 0;
return factors;
};

@@ -101,0 +101,0 @@

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -12,4 +10,2 @@

var R = _interopRequireWildcard(require("ramda"));
var _getFactors = _interopRequireDefault(require("./getFactors"));

@@ -61,13 +57,14 @@

var justification = function justification(options, line) {
var gap = line.box.width - (0, _advanceWidth.default)(line);
if (gap === 0) return; // Exact fit
var justification = function justification(options) {
return function (line) {
var gap = line.box.width - (0, _advanceWidth.default)(line);
if (gap === 0) return; // Exact fit
var factors = (0, _getFactors.default)(gap, line, options);
var distances = (0, _getDistances.default)(gap, factors);
return justifyLine(distances, line);
var factors = (0, _getFactors.default)(gap, line, options);
var distances = (0, _getDistances.default)(gap, factors);
return justifyLine(distances, line);
};
};
var _default = R.curryN(2, justification);
var _default = justification;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _bestFit = _interopRequireDefault(require("./bestFit"));

@@ -114,3 +110,7 @@

var getStyles = R.pathOr({}, ['attributedString', 'runs', 0, 'attributes']);
var getStyles = function getStyles(attributedString) {
var _attributedString$run, _attributedString$run2;
return ((_attributedString$run = attributedString.runs) === null || _attributedString$run === void 0 ? void 0 : (_attributedString$run2 = _attributedString$run[0]) === null || _attributedString$run2 === void 0 ? void 0 : _attributedString$run2.attributes) || {};
};
/**

@@ -126,26 +126,28 @@ * Performs Knuth & Plass line breaking algorithm

var lineBreaker = function lineBreaker(options, attributedString, availableWidths) {
var tolerance = options.tolerance || 4;
var style = getStyles(attributedString);
var nodes = getNodes(attributedString, style, options);
var breaks = (0, _linebreak.default)(nodes, availableWidths, {
tolerance: tolerance
}); // Try again with a higher tolerance if the line breaking failed.
while (breaks.length === 0 && tolerance < TOLERANCE_LIMIT) {
tolerance += TOLERANCE_STEPS;
breaks = (0, _linebreak.default)(nodes, availableWidths, {
var linebreaker = function linebreaker(options) {
return function (attributedString, availableWidths) {
var tolerance = options.tolerance || 4;
var style = getStyles(attributedString);
var nodes = getNodes(attributedString, style, options);
var breaks = (0, _linebreak.default)(nodes, availableWidths, {
tolerance: tolerance
});
}
}); // Try again with a higher tolerance if the line breaking failed.
if (breaks.length === 0 || breaks.length === 1 && breaks[0].position === 0) {
breaks = (0, _bestFit.default)(nodes, availableWidths);
}
while (breaks.length === 0 && tolerance < TOLERANCE_LIMIT) {
tolerance += TOLERANCE_STEPS;
breaks = (0, _linebreak.default)(nodes, availableWidths, {
tolerance: tolerance
});
}
return breakLines(attributedString, nodes, breaks.slice(1));
if (breaks.length === 0 || breaks.length === 1 && breaks[0].position === 0) {
breaks = (0, _bestFit.default)(nodes, availableWidths);
}
return breakLines(attributedString, nodes, breaks.slice(1));
};
};
var _default = R.curryN(3, lineBreaker);
var _default = linebreaker;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _unicodeProperties = _interopRequireDefault(require("@react-pdf/unicode-properties"));

@@ -26,52 +22,53 @@

var scriptItemizer = function scriptItemizer(options, attributedString) {
var string = attributedString.string;
var lastScript = 'Unknown';
var lastIndex = 0;
var index = 0;
var res = [];
if (!string) return (0, _empty.default)();
var scriptItemizer = function scriptItemizer() {
return function (attributedString) {
var string = attributedString.string;
var lastScript = 'Unknown';
var lastIndex = 0;
var index = 0;
var res = [];
if (!string) return (0, _empty.default)();
for (var i = 0; i < string.length; i += 1) {
var char = string[i];
var codePoint = char.codePointAt();
for (var i = 0; i < string.length; i += 1) {
var char = string[i];
var codePoint = char.codePointAt();
var script = _unicodeProperties.default.getScript(codePoint);
var script = _unicodeProperties.default.getScript(codePoint);
if (script !== lastScript && !ignoredScripts.includes(script)) {
if (lastScript !== 'Unknown') {
res.push({
start: lastIndex,
end: index,
attributes: {
script: lastScript
}
});
if (script !== lastScript && !ignoredScripts.includes(script)) {
if (lastScript !== 'Unknown') {
res.push({
start: lastIndex,
end: index,
attributes: {
script: lastScript
}
});
}
lastIndex = index;
lastScript = script;
}
lastIndex = index;
lastScript = script;
index += char.length;
}
index += char.length;
}
if (lastIndex < string.length) {
res.push({
start: lastIndex,
end: string.length,
attributes: {
script: lastScript
}
});
}
if (lastIndex < string.length) {
res.push({
start: lastIndex,
end: string.length,
attributes: {
script: lastScript
}
});
}
return {
string: string,
runs: res
return {
string: string,
runs: res
};
};
};
var _default = R.curryN(2, scriptItemizer);
var _default = scriptItemizer;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _ascent = _interopRequireDefault(require("../../run/ascent"));

@@ -25,119 +21,2 @@

/**
* Computes the intersections between an underline and the glyphs in
* a line fragment. Returns an array of DecorationLines omitting the
* intersections.
*/
// const intersectWithGlyphs = (line, lineFragment) => {
// // Find intersection ranges between underline and glyphs
// let x = 0;
// let y = lineFragment.ascent;
// const ranges = [];
// for (const run of lineFragment.runs) {
// if (!run.attributes.underline) {
// x += run.advanceWidth;
// continue;
// }
// for (let i = 0; i < run.glyphs.length; i++) {
// const position = run.positions[i];
// if (x >= line.rect.x && x <= line.rect.maxX) {
// const gx = x + position.xOffset;
// const gy = y + position.yOffset;
// // Standard fonts may not have a path to intersect with
// if (run.glyphs[i].path) {
// const path = run.glyphs[i].path.scale(run.scale, -run.scale).translate(gx, gy);
// const range = findPathIntersections(path, line.rect);
// if (range) {
// ranges.push(range);
// }
// }
// }
// x += position.xAdvance;
// y += position.yAdvance;
// }
// }
// if (ranges.length === 0) {
// // No intersections. Return the original line.
// return [line];
// }
// const merged = Range.merge(ranges);
// // Generate underline segments omitting the intersections,
// // but only if the space warrents an underline.
// const lines = [];
// x = line.rect.x;
// for (const { start, end } of merged) {
// if (start - x > line.rect.height) {
// lines.push(line.slice(x, start));
// }
// x = end;
// }
// if (line.rect.maxX - x > line.rect.height) {
// lines.push(line.slice(x, line.rect.maxX));
// }
// return lines;
// };
// const findIntersectionPoint = (y, x1, y1, x2, y2, range) => {
// if ((y1 < y && y2 > y) || (y1 > y && y2 < y)) {
// const x = x1 + ((y - y1) * (x2 - x1)) / (y2 - y1);
// range.extend(x);
// }
// };
/**
* Finds the intersections between a glyph path and an underline rectangle.
* It models each contour of the path a straight line, and returns a range
* containing the leftmost and rightmost intersection points, if any.
*/
// const findPathIntersections = (path, rect) => {
// let sx = 0;
// let sy = 0;
// let cx = 0;
// let cy = 0;
// let px = 0;
// let py = 0;
// const range = new Range(Infinity, -Infinity);
// const y1 = rect.y;
// const y2 = rect.maxY;
// const dialation = Math.ceil(rect.height);
// for (const { command, args } of path.commands) {
// switch (command) {
// case 'moveTo':
// sx = cx = args[0];
// sy = cy = args[1];
// continue;
// case 'lineTo':
// px = args[0];
// py = args[1];
// break;
// case 'quadraticCurveTo':
// px = args[2];
// py = args[3];
// break;
// case 'bezierCurveTo':
// px = args[4];
// py = args[5];
// break;
// case 'closePath':
// px = sx;
// py = sy;
// break;
// default:
// break;
// }
// findIntersectionPoint(y1, cx, cy, px, py, range);
// findIntersectionPoint(y2, cx, cy, px, py, range);
// if ((cy >= y1 && cy <= y2) || (cy <= y1 && cy >= y2)) {
// range.extend(cx);
// }
// cx = px;
// cy = py;
// }
// if (range.start < range.end) {
// range.start -= dialation;
// range.end += dialation;
// return range;
// }
// return null;
// };
/**
* A TextDecorationEngine is used by a Typesetter to generate

@@ -150,4 +29,4 @@ * DecorationLines for a line fragment, including underlines

return function (lineFragment) {
var x = R.propOr(0, 'overflowLeft', lineFragment);
var overflowRight = R.propOr(0, 'overflowRight', lineFragment);
var x = lineFragment.overflowLeft || 0;
var overflowRight = lineFragment.overflowRight || 0;
var maxX = (0, _advanceWidth2.default)(lineFragment) - overflowRight;

@@ -195,8 +74,4 @@ lineFragment.decorationLines = [];

x += width;
} // Adjust underline y positions, and intersect with glyph descenders.
// for (const line of underlines) {
// lineFragment.decorationLines.push(...intersectWithGlyphs(line, lineFragment));
// }
}
return lineFragment;

@@ -203,0 +78,0 @@ };

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _hyphen = _interopRequireDefault(require("hyphen"));

@@ -17,18 +13,29 @@

var _fns = require("@react-pdf/fns");
var SOFT_HYPHEN = "\xAD";
var hyphenator = (0, _hyphen.default)(_enUs.default);
var splitHyphen = R.split(SOFT_HYPHEN);
var splitHyphen = function splitHyphen(word) {
return word.split(SOFT_HYPHEN);
};
var cache = {};
var getParts = R.ifElse(R.contains(SOFT_HYPHEN), splitHyphen, R.o(splitHyphen, hyphenator));
var wordHyphenation = function wordHyphenation(options, word) {
var cacheKey = "_" + word;
if (R.isNil(word)) return [];
if (cache[cacheKey]) return cache[cacheKey];
cache[cacheKey] = getParts(word);
return cache[cacheKey];
var getParts = function getParts(word) {
var base = word.includes(SOFT_HYPHEN) ? word : hyphenator(word);
return splitHyphen(base);
};
var _default = R.curryN(2, wordHyphenation);
var wordHyphenation = function wordHyphenation() {
return function (word) {
var cacheKey = "_" + word;
if ((0, _fns.isNil)(word)) return [];
if (cache[cacheKey]) return cache[cacheKey];
cache[cacheKey] = getParts(word);
return cache[cacheKey];
};
};
var _default = wordHyphenation;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var WHITE_SPACES_CODES = [32];
var WHITE_SPACES_CODE = 32;
/**

@@ -18,4 +13,8 @@ * Check if glyph is white space

var isWhiteSpace = R.compose(R.not, R.isEmpty, R.intersection(WHITE_SPACES_CODES), R.propOr([], 'codePoints'));
var isWhiteSpace = function isWhiteSpace(glyph) {
var codePoints = (glyph === null || glyph === void 0 ? void 0 : glyph.codePoints) || [];
return codePoints.includes(WHITE_SPACES_CODE);
};
var _default = isWhiteSpace;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -24,3 +20,3 @@ * Slice glyph between codePoints range

if (start === 0 && end === glyph.codePoints.length) return [glyph];
var codePoints = R.slice(start, end, glyph.codePoints);
var codePoints = glyph.codePoints.slice(start, end);
var string = String.fromCodePoint.apply(String, codePoints);

@@ -30,4 +26,3 @@ return font ? font.layout(string).glyphs : [glyph];

var _default = R.curryN(4, slice);
var _default = slice;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -20,9 +18,9 @@ /**

var appendIndices = function appendIndices(length, indices) {
return R.converge(R.concat, [R.identity, R.converge(R.repeat, [R.either(R.o(R.inc, R.last), // Value should be last plus 1
R.always(0) // Or zero if inserting at beggining
), R.always(length)])])(indices);
var lastIndex = (0, _fns.last)(indices);
var value = (0, _fns.isNil)(lastIndex) ? 0 : lastIndex + 1;
var newIndices = Array(length).fill(value);
return indices.concat(newIndices);
};
var _default = R.curryN(2, appendIndices);
var _default = appendIndices;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -17,3 +13,6 @@ * Returns new array starting with zero, and keeping same relation between consecutive values

var normalize = function normalize(array) {
return R.map(R.subtract(R.__, R.head(array)))(array);
var head = array[0];
return array.map(function (value) {
return value - head;
});
};

@@ -20,0 +19,0 @@

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -21,7 +17,10 @@ * Prepend glyph indices with given length

if (length === 0) return indices;
return R.converge(R.concat, [R.converge(R.repeat, [R.always(0), R.always(length)]), R.map(R.inc)])(indices);
var newIndices = Array(length).fill(0);
var lastIndices = indices.map(function (value) {
return value + 1;
});
return newIndices.concat(lastIndices);
};
var _default = R.curryN(2, prepend);
var _default = prepend;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var applyAttributes = function applyAttributes(a) {
return {
align: a.align || 'left',
alignLastLine: a.alignLastLine || (a.align === 'justify' ? 'left' : a.align || 'left'),
attachment: a.attachment || null,
backgroundColor: a.backgroundColor || null,
bidiLevel: a.bidiLevel || null,
bullet: a.bullet || null,
characterSpacing: a.characterSpacing || 0,
color: a.color || 'black',
features: a.features || [],
fill: a.fill !== false,
font: a.font || null,
fontSize: a.fontSize || 12,
hangingPunctuation: a.hangingPunctuation || false,
hyphenationFactor: a.hyphenationFactor || 0,
indent: a.indent || 0,
justificationFactor: a.justificationFactor || 1,
lineHeight: a.lineHeight || null,
lineSpacing: a.lineSpacing || 0,
link: a.link || null,
marginLeft: a.marginLeft || a.margin || 0,
marginRight: a.marginRight || a.margin || 0,
opacity: a.opacity,
paddingTop: a.paddingTop || a.padding || 0,
paragraphSpacing: a.paragraphSpacing || 0,
underline: a.underline || false,
underlineColor: a.underlineColor || a.color || 'black',
underlineStyle: a.underlineStyle || 'solid',
script: a.script || null,
shrinkFactor: a.shrinkFactor || 0,
strike: a.strike || false,
strikeColor: a.strikeColor || a.color || 'black',
strikeStyle: a.strikeStyle || 'solid',
stroke: a.stroke || false,
wordSpacing: a.wordSpacing || 0,
yOffset: a.yOffset || 0
};
};
/**

@@ -16,43 +51,10 @@ * Apply default style to run

*/
var applyRunStyles = R.evolve({
attributes: function attributes(a) {
return {
align: a.align || 'left',
alignLastLine: a.alignLastLine || (a.align === 'justify' ? 'left' : a.align || 'left'),
attachment: a.attachment || null,
backgroundColor: a.backgroundColor || null,
bidiLevel: a.bidiLevel || null,
bullet: a.bullet || null,
characterSpacing: a.characterSpacing || 0,
color: a.color || 'black',
features: a.features || [],
fill: a.fill !== false,
font: a.font || null,
fontSize: a.fontSize || 12,
hangingPunctuation: a.hangingPunctuation || false,
hyphenationFactor: a.hyphenationFactor || 0,
indent: a.indent || 0,
justificationFactor: a.justificationFactor || 1,
lineHeight: a.lineHeight || null,
lineSpacing: a.lineSpacing || 0,
link: a.link || null,
marginLeft: a.marginLeft || a.margin || 0,
marginRight: a.marginRight || a.margin || 0,
opacity: a.opacity,
paddingTop: a.paddingTop || a.padding || 0,
paragraphSpacing: a.paragraphSpacing || 0,
underline: a.underline || false,
underlineColor: a.underlineColor || a.color || 'black',
underlineStyle: a.underlineStyle || 'solid',
script: a.script || null,
shrinkFactor: a.shrinkFactor || 0,
strike: a.strike || false,
strikeColor: a.strikeColor || a.color || 'black',
strikeStyle: a.strikeStyle || 'solid',
stroke: a.stroke || false,
wordSpacing: a.wordSpacing || 0,
yOffset: a.yOffset || 0
};
}
});
var applyRunStyles = function applyRunStyles(run) {
var attributes = applyAttributes(run.attributes);
return Object.assign({}, run, {
attributes: attributes
});
};
/**

@@ -67,7 +69,12 @@ * Apply default attributes for an attributed string

var applyDefaultStyles = function applyDefaultStyles() {
return R.applySpec({
string: R.propOr('', 'string'),
runs: R.compose(R.map(applyRunStyles), R.defaultTo([]), R.prop('runs'))
});
return function (attributedString) {
var string = attributedString.string || '';
var runs = (attributedString.runs || []).map(applyRunStyles);
return {
string: string,
runs: runs
};
};
};

@@ -74,0 +81,0 @@

@@ -5,8 +5,6 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -32,5 +30,13 @@ var _advanceWidth = _interopRequireDefault(require("../attributedString/advanceWidth"));

var removeNewLine = R.when(R.compose(R.equals('\n'), R.last, R.prop('string')), _dropLast.default);
var getOverflowLeft = R.converge(R.add, [R.propOr(0, 'overflowLeft'), _leadingOffset.default]);
var getOverflowRight = R.converge(R.add, [R.propOr(0, 'overflowRight'), _trailingOffset.default]);
var removeNewLine = function removeNewLine(line) {
return (0, _fns.last)(line.string) === '\n' ? (0, _dropLast.default)(line) : line;
};
var getOverflowLeft = function getOverflowLeft(line) {
return (0, _leadingOffset.default)(line) + (line.overflowLeft || 0);
};
var getOverflowRight = function getOverflowRight(line) {
return (0, _trailingOffset.default)(line) + (line.overflowRight || 0);
};
/**

@@ -43,11 +49,17 @@ * Ignore whitespace at the start and end of a line for alignment

var adjustOverflow = function adjustOverflow(line) {
var overflowLeft = getOverflowLeft(line);
var overflowRight = getOverflowRight(line);
return R.compose(R.assoc('overflowLeft', overflowLeft), R.assoc('overflowRight', overflowRight), R.evolve({
box: R.evolve({
x: R.subtract(R.__, overflowLeft),
width: R.add(overflowLeft + overflowRight)
})
}))(line);
var x = line.box.x - overflowLeft;
var width = line.box.width + overflowLeft + overflowRight;
var box = Object.assign({}, line.box, {
x: x,
width: width
});
return Object.assign({}, line, {
box: box,
overflowLeft: overflowLeft,
overflowRight: overflowRight
});
};

@@ -71,7 +83,10 @@ /**

var shouldJustify = align === 'justify' || lineWidth > line.box.width;
return R.compose(R.when(R.always(shouldJustify), engines.justification(options)), R.evolve({
box: R.evolve({
x: R.add(remainingWidth * alignFactor)
})
}))(line);
var x = line.box.x + remainingWidth * alignFactor;
var box = Object.assign({}, line.box, {
x: x
});
var newLine = Object.assign({}, line, {
box: box
});
return shouldJustify ? engines.justification(options)(newLine) : newLine;
};

@@ -98,6 +113,8 @@ };

return function (line, i, lines) {
var _line$runs, _line$runs$;
var isLastFragment = i === lines.length - 1;
var style = R.pathOr({}, ['runs', 0, 'attributes'], line);
var style = ((_line$runs = line.runs) === null || _line$runs === void 0 ? void 0 : (_line$runs$ = _line$runs[0]) === null || _line$runs$ === void 0 ? void 0 : _line$runs$.attributes) || {};
var align = isLastFragment ? style.alignLastLine : style.align;
return R.compose(engines.textDecoration(options), justifyLine(engines, options, align), adjustOverflow, removeNewLine)(line);
return (0, _fns.compose)(engines.textDecoration(options), justifyLine(engines, options, align), adjustOverflow, removeNewLine)(line);
};

@@ -116,11 +133,12 @@ };

var finalizeFragments = function finalizeFragments(engines, options, blocks) {
var blockFinalizer = finalizeBlock(engines, options);
return blocks.map(function (block) {
return block.map(blockFinalizer);
});
var finalizeFragments = function finalizeFragments(engines, options) {
return function (blocks) {
var blockFinalizer = finalizeBlock(engines, options);
return blocks.map(function (block) {
return block.map(blockFinalizer);
});
};
};
var _default = R.curryN(3, finalizeFragments);
var _default = finalizeFragments;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -12,4 +10,2 @@

var R = _interopRequireWildcard(require("ramda"));
var _scale = _interopRequireDefault(require("../run/scale"));

@@ -19,3 +15,7 @@

var getCharacterSpacing = R.pathOr(0, ['attributes', 'characterSpacing']);
var getCharacterSpacing = function getCharacterSpacing(run) {
var _run$attributes;
return ((_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : _run$attributes.characterSpacing) || 0;
};
/**

@@ -29,15 +29,16 @@ * Scale run positions

var scalePositions = function scalePositions(run, positions) {
var multScale = R.multiply((0, _scale.default)(run));
var runScale = (0, _scale.default)(run);
var characterSpacing = getCharacterSpacing(run);
var scalePosition = R.evolve({
xAdvance: R.o(R.add(characterSpacing), multScale),
yAdvance: multScale,
xOffset: multScale,
yOffset: multScale
return positions.map(function (position, i) {
var isLast = i === positions.length;
var xSpacing = isLast ? 0 : characterSpacing;
return Object.assign({}, position, {
xAdvance: position.xAdvance * runScale + xSpacing,
yAdvance: position.yAdvance * runScale,
xOffset: position.xOffset * runScale,
yOffset: position.yOffset * runScale
});
});
var subCharacterSpacing = R.evolve({
xAdvance: R.subtract(R.__, characterSpacing)
});
return R.compose(R.adjust(-1, subCharacterSpacing), R.map(scalePosition))(positions);
};

@@ -57,4 +58,4 @@ /**

end = run.end,
_run$attributes = run.attributes,
attributes = _run$attributes === void 0 ? {} : _run$attributes;
_run$attributes2 = run.attributes,
attributes = _run$attributes2 === void 0 ? {} : _run$attributes2;
var font = attributes.font;

@@ -89,5 +90,6 @@ if (!font) return (0, _extends2.default)({}, run, {

return function (attributedString) {
return R.evolve({
runs: R.map(layoutRun(attributedString.string))
})(attributedString);
var runs = attributedString.runs.map(layoutRun(attributedString.string));
return Object.assign({}, attributedString, {
runs: runs
});
};

@@ -94,0 +96,0 @@ };

@@ -5,8 +5,6 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -44,13 +42,19 @@ var _wrapWords = _interopRequireDefault(require("./wrapWords"));

*/
var layoutEngine = function layoutEngine(engines, attributedString, container, options) {
if (options === void 0) {
options = {};
}
var layoutEngine = function layoutEngine(engines) {
return function (attributedString, container, options) {
if (options === void 0) {
options = {};
}
var processParagraphs = R.compose((0, _resolveYOffset.default)(engines, options), (0, _resolveAttachments.default)(engines, options), (0, _generateGlyphs.default)(engines, options), (0, _wrapWords.default)(engines, options));
return R.compose((0, _finalizeFragments.default)(engines, options), (0, _typesetter.default)(engines, options, container), R.map(processParagraphs), (0, _splitParagraphs.default)(engines, options), (0, _preprocessRuns.default)(engines, options), (0, _applyDefaultStyles.default)(engines, options))(attributedString);
var processParagraph = (0, _fns.compose)((0, _resolveYOffset.default)(engines, options), (0, _resolveAttachments.default)(engines, options), (0, _generateGlyphs.default)(engines, options), (0, _wrapWords.default)(engines, options));
var processParagraphs = function processParagraphs(paragraphs) {
return paragraphs.map(processParagraph);
};
return (0, _fns.compose)((0, _finalizeFragments.default)(engines, options), (0, _typesetter.default)(engines, options, container), processParagraphs, (0, _splitParagraphs.default)(engines, options), (0, _preprocessRuns.default)(engines, options), (0, _applyDefaultStyles.default)(engines, options))(attributedString);
};
};
var _default = R.curryN(3, layoutEngine);
var _default = layoutEngine;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _omit = _interopRequireDefault(require("../run/omit"));

@@ -26,5 +22,12 @@

var purgeAttachments = R.when(R.compose(R.not, R.includes(ATTACHMENT_CODE), R.prop('string')), R.evolve({
runs: R.map((0, _omit.default)('attachment'))
}));
var purgeAttachments = function purgeAttachments(attributedString) {
var shouldPurge = !attributedString.string.includes(ATTACHMENT_CODE);
if (!shouldPurge) return attributedString;
var runs = attributedString.runs.map(function (run) {
return (0, _omit.default)('attachment', run);
});
return Object.assign({}, attributedString, {
runs: runs
});
};
/**

@@ -38,9 +41,14 @@ * Layout paragraphs inside rectangle

var layoutLines = function layoutLines(rect, lines, indent) {
var currentY = rect.y;
return R.addIndex(R.map)(R.compose(purgeAttachments, function (line, i) {
return lines.map(function (line, i) {
var _line$runs, _line$runs$;
var lineIndent = i === 0 ? indent : 0;
var style = R.pathOr({}, ['runs', 0, 'attributes'], line);
var style = ((_line$runs = line.runs) === null || _line$runs === void 0 ? void 0 : (_line$runs$ = _line$runs[0]) === null || _line$runs$ === void 0 ? void 0 : _line$runs$.attributes) || {};
var height = Math.max((0, _height.default)(line), style.lineHeight);
var box = {
var newLine = Object.assign({}, line);
delete newLine.syllables;
newLine.box = {
x: rect.x + lineIndent,

@@ -52,4 +60,4 @@ y: currentY,

currentY += height;
return R.compose(R.assoc('box', box), R.omit(['syllables']))(line);
}))(lines);
return purgeAttachments(newLine);
});
};

@@ -69,6 +77,8 @@ /**

return function (rect, paragraph) {
var indent = R.pathOr(0, ['runs', 0, 'attributes', 'indent'], paragraph);
var lines = engines.linebreaker(options)(paragraph, [rect.width - indent, rect.width]);
var lineFragments = layoutLines(rect, lines, indent);
return lineFragments;
var _paragraph$runs, _paragraph$runs$, _paragraph$runs$$attr;
var indent = ((_paragraph$runs = paragraph.runs) === null || _paragraph$runs === void 0 ? void 0 : (_paragraph$runs$ = _paragraph$runs[0]) === null || _paragraph$runs$ === void 0 ? void 0 : (_paragraph$runs$$attr = _paragraph$runs$.attributes) === null || _paragraph$runs$$attr === void 0 ? void 0 : _paragraph$runs$$attr.indent) || 0;
var availableWidths = [rect.width - indent, rect.width];
var lines = engines.linebreaker(options)(paragraph, availableWidths);
return layoutLines(rect, lines, indent);
};

@@ -75,0 +85,0 @@ };

@@ -5,8 +5,6 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -19,5 +17,10 @@ var _omit = _interopRequireDefault(require("../run/omit"));

var omitFont = R.evolve({
runs: R.map((0, _omit.default)('font'))
});
var omitFont = function omitFont(attributedString) {
var runs = attributedString.runs.map(function (run) {
return (0, _omit.default)('font', run);
});
return Object.assign({}, attributedString, {
runs: runs
});
};
/**

@@ -32,9 +35,25 @@ * Performs font substitution and script itemization on attributed string

var preprocessRuns = function preprocessRuns(engines, options) {
return R.ifElse(R.isNil, _empty.default, R.applySpec({
string: R.prop('string'),
runs: R.compose(_flatten.default, R.flatten, R.pluck('runs'), R.juxt([engines.fontSubstitution(options), // font substitution
engines.scriptItemizer(options), // script itemization
omitFont]))
}));
return function (attributedString) {
if ((0, _fns.isNil)(attributedString)) return (0, _empty.default)();
var string = attributedString.string;
var fontSubstitution = engines.fontSubstitution,
scriptItemizer = engines.scriptItemizer;
var _omitFont = omitFont(attributedString),
omittedFontRuns = _omitFont.runs;
var _fontSubstitution = fontSubstitution(options)(attributedString),
substitutedRuns = _fontSubstitution.runs;
var _scriptItemizer = scriptItemizer(options)(attributedString),
itemizationRuns = _scriptItemizer.runs;
var runs = substitutedRuns.concat(itemizationRuns).concat(omittedFontRuns);
return {
string: string,
runs: (0, _flatten.default)(runs)
};
};
};

@@ -41,0 +60,0 @@

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var ATTACHMENT_CODE = 0xfffc; // 65532
var mapIndexed = R.addIndex(R.map);
var getGlyphs = R.propOr([], 'glyphs');
var getAttachment = R.pathOr({}, ['attributes', 'attachment']);
var isReplaceGlyph = R.o(R.includes(ATTACHMENT_CODE), R.propOr([], 'codePoints'));
var isReplaceGlyph = function isReplaceGlyph(glyph) {
return glyph.codePoints.includes(ATTACHMENT_CODE);
};
/**

@@ -23,19 +17,23 @@ * Resolve attachments of run

var resolveRunAttachments = function resolveRunAttachments(run) {
var glyphs = getGlyphs(run);
var attachment = getAttachment(run);
var attachmentWidth = R.always(attachment.width);
return R.evolve({
positions: mapIndexed(function (position, i) {
var glyph = glyphs[i];
var _run$attributes;
if (attachment && attachment.width && isReplaceGlyph(glyph)) {
return R.evolve({
xAdvance: attachmentWidth
}, position);
}
if (!run.positions) return run;
var glyphs = run.glyphs || [];
var attachment = ((_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : _run$attributes.attachment) || {};
var positions = run.positions.map(function (position, i) {
var glyph = glyphs[i];
return R.clone(position);
})
})(run);
if (attachment && attachment.width && isReplaceGlyph(glyph)) {
return Object.assign({}, position, {
xAdvance: attachment.width
});
}
return Object.assign({}, position);
});
return Object.assign({}, run, {
positions: positions
});
};

@@ -53,5 +51,8 @@ /**

var resolveAttachments = function resolveAttachments() {
return R.evolve({
runs: R.map(resolveRunAttachments)
});
return function (attributedString) {
var runs = attributedString.runs.map(resolveRunAttachments);
return Object.assign({}, attributedString, {
runs: runs
});
};
};

@@ -58,0 +59,0 @@

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var getYOffset = R.pathOr(0, ['attributes', 'yOffset']);
var getUnitsPerEm = R.pathOr(0, ['attributes', 'font', 'unitsPerEm']);
/**

@@ -18,10 +12,16 @@ * Resolves yOffset for run

*/
var resolveRunYOffset = function resolveRunYOffset(run) {
var _run$attributes, _run$attributes$font, _run$attributes2;
var resolveRunYOffset = function resolveRunYOffset(run) {
var unitsPerEm = getUnitsPerEm(run);
var yOffset = getYOffset(run);
var mult = yOffset * unitsPerEm;
return R.evolve({
positions: R.map(R.assoc('yOffset', mult))
})(run);
if (!run.positions) return run;
var unitsPerEm = ((_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : (_run$attributes$font = _run$attributes.font) === null || _run$attributes$font === void 0 ? void 0 : _run$attributes$font.unitsPerEm) || 0;
var yOffset = (((_run$attributes2 = run.attributes) === null || _run$attributes2 === void 0 ? void 0 : _run$attributes2.yOffset) || 0) * unitsPerEm;
var positions = run.positions.map(function (p) {
return Object.assign({}, p, {
yOffset: yOffset
});
});
return Object.assign({}, run, {
positions: positions
});
};

@@ -39,5 +39,8 @@ /**

var resolveYOffset = function resolveYOffset() {
return R.evolve({
runs: R.map(resolveRunYOffset)
});
return function (attributedString) {
var runs = attributedString.runs.map(resolveRunYOffset);
return Object.assign({}, attributedString, {
runs: runs
});
};
};

@@ -44,0 +47,0 @@

@@ -5,8 +5,6 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -17,4 +15,2 @@ var _copy = _interopRequireDefault(require("../rect/copy"));

var _slice = _interopRequireDefault(require("../block/slice"));
var _height = _interopRequireDefault(require("../block/height"));

@@ -38,34 +34,35 @@

*/
var typesetter = function typesetter(engines, options, container, attributedStrings) {
var blocks = [];
var paragraphs = [].concat(attributedStrings);
var layoutBlock = (0, _layoutParagraph.default)(engines, options);
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();
var typesetter = function typesetter(engines, options, container) {
return function (attributedStrings) {
var blocks = [];
var paragraphs = [].concat(attributedStrings);
var layoutBlock = (0, _layoutParagraph.default)(engines, options);
var maxLines = (0, _fns.isNil)(container.maxLines) ? Infinity : container.maxLines;
var truncateEllipsis = container.truncateMode === 'ellipsis';
var linesCount = maxLines;
var paragraphRect = (0, _copy.default)(container);
var nextParagraph = paragraphs.shift();
while (linesCount > 0 && nextParagraph) {
var block = layoutBlock(paragraphRect, nextParagraph);
var slicedBlock = (0, _slice.default)(linesCount, block);
var linesHeight = (0, _height.default)(slicedBlock);
var shouldTruncate = truncateEllipsis && block.length !== slicedBlock.length;
linesCount -= slicedBlock.length;
while (linesCount > 0 && nextParagraph) {
var block = layoutBlock(paragraphRect, nextParagraph);
var slicedBlock = block.slice(0, linesCount);
var linesHeight = (0, _height.default)(slicedBlock);
var shouldTruncate = truncateEllipsis && block.length !== slicedBlock.length;
linesCount -= slicedBlock.length;
if (paragraphRect.height >= linesHeight) {
blocks.push(R.when(R.always(shouldTruncate), _truncate.default)(slicedBlock));
paragraphRect = (0, _crop.default)(linesHeight, paragraphRect);
nextParagraph = paragraphs.shift();
} else {
blocks.push(R.compose(_truncate.default, (0, _sliceAtHeight.default)(paragraphRect.height))(slicedBlock));
break;
if (paragraphRect.height >= linesHeight) {
blocks.push(shouldTruncate ? (0, _truncate.default)(slicedBlock) : slicedBlock);
paragraphRect = (0, _crop.default)(linesHeight, paragraphRect);
nextParagraph = paragraphs.shift();
} else {
blocks.push((0, _truncate.default)((0, _sliceAtHeight.default)(paragraphRect.height, slicedBlock)));
break;
}
}
}
return blocks;
return blocks;
};
};
var _default = R.curryN(4, typesetter);
var _default = typesetter;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -12,4 +10,2 @@

var R = _interopRequireWildcard(require("ramda"));
var _fromFragments = _interopRequireDefault(require("../attributedString/fromFragments"));

@@ -37,3 +33,3 @@

var wrapWords = function wrapWords(engines, options, attributedString) {
var wrapWords = function wrapWords(engines, options) {
if (engines === void 0) {

@@ -47,31 +43,34 @@ engines = {};

var syllables = [];
var fragments = [];
var hyphenateWord = options.hyphenationCallback || engines.wordHyphenation && engines.wordHyphenation(options) || defaultHyphenationEngine;
return function (attributedString) {
var _engines$wordHyphenat, _engines;
for (var i = 0; i < attributedString.runs.length; i += 1) {
var string = '';
var run = attributedString.runs[i];
var words = attributedString.string.slice(run.start, run.end).split(/([ ]+)/g).filter(Boolean);
var syllables = [];
var fragments = [];
var hyphenateWord = options.hyphenationCallback || ((_engines$wordHyphenat = (_engines = engines).wordHyphenation) === null || _engines$wordHyphenat === void 0 ? void 0 : _engines$wordHyphenat.call(_engines, options)) || defaultHyphenationEngine;
for (var j = 0; j < words.length; j += 1) {
var word = words[j];
var parts = hyphenateWord(word);
syllables.push.apply(syllables, parts);
string += parts.join('');
for (var i = 0; i < attributedString.runs.length; i += 1) {
var string = '';
var run = attributedString.runs[i];
var words = attributedString.string.slice(run.start, run.end).split(/([ ]+)/g).filter(Boolean);
for (var j = 0; j < words.length; j += 1) {
var word = words[j];
var parts = hyphenateWord(word);
syllables.push.apply(syllables, parts);
string += parts.join('');
}
fragments.push({
string: string,
attributes: run.attributes
});
}
fragments.push({
string: string,
attributes: run.attributes
return (0, _extends2.default)({}, (0, _fromFragments.default)(fragments), {
syllables: syllables
});
}
return (0, _extends2.default)({}, (0, _fromFragments.default)(fragments), {
syllables: syllables
});
};
};
var _default = R.curryN(3, wrapWords);
var _default = wrapWords;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -16,4 +12,7 @@ * Returns rect area

*/
var area = R.converge(R.multiply, [R.propOr(0, 'height'), R.propOr(0, 'width')]);
var area = function area(rect) {
return rect ? rect.height * rect.width : 0;
};
var _default = area;
exports.default = _default;

@@ -5,11 +5,11 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _maxY = _interopRequireDefault(require("./maxY"));
var ZERO = {
x: 0,
y: 0
};
/**

@@ -21,7 +21,11 @@ * Returns rect bottom left point

*/
var bottomLeft = R.applySpec({
x: R.propOr(0, 'x'),
y: _maxY.default
});
var bottomLeft = function bottomLeft(rect) {
return rect ? {
x: rect.x || 0,
y: (0, _maxY.default)(rect)
} : ZERO;
};
var _default = bottomLeft;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _maxX = _interopRequireDefault(require("./maxX"));

@@ -23,7 +19,10 @@

*/
var bottomRight = R.applySpec({
x: _maxX.default,
y: _maxY.default
});
var bottomRight = function bottomRight(rect) {
return {
x: (0, _maxX.default)(rect),
y: (0, _maxY.default)(rect)
};
};
var _default = bottomRight;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -16,4 +12,7 @@ * Clone rect

*/
var copy = R.clone;
var copy = function copy(rect) {
return Object.assign({}, rect);
};
var _default = copy;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -17,10 +13,11 @@ * Crop upper section of rect

var crop = function crop(height, rect) {
return R.evolve({
y: R.add(height),
height: R.subtract(R.__, height)
})(rect);
var y = rect.y + height;
var h = rect.height - height;
return Object.assign({}, rect, {
y: y,
height: h
});
};
var _default = R.curryN(2, crop);
var _default = crop;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -15,9 +11,12 @@ * Returns empty rect

*/
var empty = R.always({
x: 0,
y: 0,
width: 0,
height: 0
});
var empty = function empty() {
return {
x: 0,
y: 0,
width: 0,
height: 0
};
};
var _default = empty;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -18,4 +14,7 @@ * Check if two rect are equal

*/
var equals = R.equals;
var equals = function equals(a, b) {
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
};
var _default = equals;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -16,4 +12,7 @@ * Returns max rect X coordinate

*/
var maxX = R.converge(R.add, [R.propOr(0, 'x'), R.propOr(0, 'width')]);
var maxX = function maxX(rect) {
return rect ? rect.x + rect.width : 0;
};
var _default = maxX;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -16,4 +12,7 @@ * Returns max rect Y coordinate

*/
var maxY = R.converge(R.add, [R.propOr(0, 'y'), R.propOr(0, 'height')]);
var maxY = function maxY(rect) {
return rect ? rect.y + rect.height : 0;
};
var _default = maxY;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -18,10 +14,11 @@ * Add scalar to run

var add = function add(n, run) {
return R.evolve({
start: R.add(n),
end: R.add(n)
})(run);
var start = run.start + n;
var end = run.end + n;
return Object.assign({}, run, {
start: start,
end: end
});
};
var _default = R.curryN(2, add);
var _default = add;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -8,3 +8,3 @@ exports.__esModule = true;

var R = _interopRequireWildcard(require("ramda"));
var _advanceWidth = _interopRequireDefault(require("../positions/advanceWidth"));

@@ -17,4 +17,7 @@ /**

*/
var advanceWidth = R.compose(R.reduce(R.useWith(R.add, [R.identity, R.propOr(0, 'xAdvance')]), 0), R.propOr([], 'positions'));
var advanceWidth = function advanceWidth(run) {
return (0, _advanceWidth.default)(run.positions || []);
};
var _default = advanceWidth;
exports.default = _default;

@@ -5,11 +5,9 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _glyphIndexAt = _interopRequireDefault(require("./glyphIndexAt"));
var _advanceWidth = _interopRequireDefault(require("../positions/advanceWidth"));
/**

@@ -24,10 +22,10 @@ * Advance width between two string indices

var advanceWidthBetween = function advanceWidthBetween(start, end, run) {
var runStart = R.propOr(0, 'start', run);
var runStart = run.start || 0;
var glyphStartIndex = Math.max(0, (0, _glyphIndexAt.default)(start - runStart, run));
var glyphEndIndex = Math.max(0, (0, _glyphIndexAt.default)(end - runStart, run));
return R.compose(R.reduce(R.useWith(R.add, [R.identity, R.propOr(0, 'xAdvance')]), 0), R.slice(glyphStartIndex, glyphEndIndex), R.propOr([], 'positions'))(run);
var positions = (run.positions || []).slice(glyphStartIndex, glyphEndIndex);
return (0, _advanceWidth.default)(positions);
};
var _default = R.curryN(3, advanceWidthBetween);
var _default = advanceWidthBetween;
exports.default = _default;

@@ -5,11 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _copy = _interopRequireDefault(require("./copy"));
var _scale = _interopRequireDefault(require("./scale"));

@@ -33,12 +27,22 @@

var appendGlyph = function appendGlyph(glyph, run) {
var runScale = (0, _scale.default)(run);
var glyphLength = R.length(glyph.codePoints);
return R.evolve({
end: R.add(glyphLength),
glyphs: R.append(glyph),
glyphIndices: (0, _append.default)(glyphLength),
positions: R.append({
xAdvance: glyph.advanceWidth * runScale
})
})(run);
var _glyph$codePoints;
var glyphLength = ((_glyph$codePoints = glyph.codePoints) === null || _glyph$codePoints === void 0 ? void 0 : _glyph$codePoints.length) || 0;
var end = run.end + glyphLength;
var glyphs = run.glyphs.concat(glyph);
var glyphIndices = (0, _append.default)(glyphLength, run.glyphIndices);
if (!run.positions) return Object.assign({}, run, {
end: end,
glyphs: glyphs,
glyphIndices: glyphIndices
});
var positions = run.positions.concat({
xAdvance: glyph.advanceWidth * (0, _scale.default)(run)
});
return Object.assign({}, run, {
end: end,
glyphs: glyphs,
glyphIndices: glyphIndices,
positions: positions
});
};

@@ -55,3 +59,3 @@ /**

var append = function append(value, run) {
if (!value) return (0, _copy.default)(run);
if (!value) return run;
var font = (0, _getFont.default)(run);

@@ -62,4 +66,3 @@ var glyph = (0, _isNumber.default)(value) ? (0, _fromCodePoint.default)(value, font) : value;

var _default = R.curryN(2, append);
var _default = append;
exports.default = _default;

@@ -5,12 +5,7 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _scale = _interopRequireDefault(require("./scale"));
var getFontAscent = R.ifElse(R.has('attributes'), R.pathOr(0, ['attributes', 'font', 'ascent']), R.always(0));
/**

@@ -22,5 +17,11 @@ * Get run ascent

*/
var ascent = function ascent(run) {
var _run$attributes, _run$attributes$attac, _run$attributes2, _run$attributes2$font;
var ascent = R.converge(R.max, [R.pathOr(0, ['attributes', 'attachment', 'height']), R.converge(R.multiply, [_scale.default, getFontAscent])]);
var attachmentHeight = ((_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : (_run$attributes$attac = _run$attributes.attachment) === null || _run$attributes$attac === void 0 ? void 0 : _run$attributes$attac.height) || 0;
var fontAscent = ((_run$attributes2 = run.attributes) === null || _run$attributes2 === void 0 ? void 0 : (_run$attributes2$font = _run$attributes2.font) === null || _run$attributes2$font === void 0 ? void 0 : _run$attributes2$font.ascent) || 0;
return Math.max(attachmentHeight, fontAscent * (0, _scale.default)(run));
};
var _default = ascent;
exports.default = _default;

@@ -5,8 +5,6 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -17,4 +15,2 @@ var _length = _interopRequireDefault(require("./length"));

var reverseMerge = R.flip(R.merge);
var reverseConcat = R.flip(R.concat);
/**

@@ -27,15 +23,23 @@ * Concats two runs into one

*/
var concat = function concat(runA, runB) {
return R.evolve({
end: R.add((0, _length.default)(runB)),
glyphs: reverseConcat(R.prop('glyphs', runB)),
positions: reverseConcat(R.prop('positions', runB)),
attributes: reverseMerge(R.prop('attributes', runB)),
glyphIndices: R.compose(_normalize.default, reverseConcat(R.map(R.compose(R.inc, R.add(R.last(R.propOr([], 'glyphIndices', runA)) || 0)), R.propOr([], 'glyphIndices', runB))))
})(runA);
var end = runA.end + (0, _length.default)(runB);
var glyphs = (runA.glyphs || []).concat(runB.glyphs || []);
var positions = (runA.positions || []).concat(runB.positions || []);
var attributes = Object.assign({}, runA.attributes, runB.attributes);
var runAIndices = runA.glyphIndices || [];
var runALastIndex = (0, _fns.last)(runAIndices) || 0;
var runBIndices = (runB.glyphIndices || []).map(function (i) {
return i + runALastIndex + 1;
});
var glyphIndices = (0, _normalize.default)(runAIndices.concat(runBIndices));
return Object.assign({}, runA, {
end: end,
glyphs: glyphs,
positions: positions,
attributes: attributes,
glyphIndices: glyphIndices
});
};
var _default = R.curryN(2, concat);
var _default = concat;
exports.default = _default;

@@ -5,12 +5,7 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _scale = _interopRequireDefault(require("./scale"));
var getFontDescent = R.ifElse(R.has('attributes'), R.pathOr(0, ['attributes', 'font', 'descent']), R.always(0));
/**

@@ -22,5 +17,10 @@ * Get run descent

*/
var descent = function descent(run) {
var _run$attributes, _run$attributes$font;
var descent = R.converge(R.multiply, [_scale.default, getFontDescent]);
var fontDescent = ((_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : (_run$attributes$font = _run$attributes.font) === null || _run$attributes$font === void 0 ? void 0 : _run$attributes$font.descent) || 0;
return (0, _scale.default)(run) * fontDescent;
};
var _default = descent;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -15,11 +11,14 @@ * Returns empty run

*/
var empty = R.always({
start: 0,
end: 0,
glyphIndices: [],
glyphs: [],
positions: [],
attributes: {}
});
var empty = function empty() {
return {
start: 0,
end: 0,
glyphIndices: [],
glyphs: [],
positions: [],
attributes: {}
};
};
var _default = empty;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _runIndexAt = _interopRequireDefault(require("./runIndexAt"));

@@ -25,8 +21,7 @@

var startIndex = (0, _runIndexAt.default)(start, runs);
var endIndex = R.max((0, _runIndexAt.default)(end - 1, runs), startIndex);
return R.slice(startIndex, endIndex + 1, runs);
var endIndex = Math.max((0, _runIndexAt.default)(end - 1, runs), startIndex);
return runs.slice(startIndex, endIndex + 1);
};
var _default = R.curryN(3, filter);
var _default = filter;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _sort = _interopRequireDefault(require("./sort"));

@@ -21,11 +17,31 @@

var mergeAttributes = function mergeAttributes(key, left, right) {
return key === 'attributes' ? R.merge(left, right) : right;
var generatePoints = function generatePoints(runs) {
var result = runs.reduce(function (acc, run, i) {
return acc.concat([['start', run.start, run.attributes, i], ['end', run.end, run.attributes, i]]);
}, []);
return result.sort(sortPoints);
};
var generatePoints = R.o(R.sort(sortPoints), R.addIndex(R.chain)(function (run, i) {
return [['start', run.start, run.attributes, i], ['end', run.end, run.attributes, i]];
}));
var flattenEmptyRuns = R.compose(R.map(R.reduce(R.mergeDeepWithKey(mergeAttributes), {})), R.groupWith(R.eqProps('start')));
var mergeRuns = function mergeRuns(runs) {
return runs.reduce(function (acc, run) {
var attributes = Object.assign({}, acc.attributes, run.attributes);
return Object.assign({}, run, {
attributes: attributes
});
}, {});
};
var groupEmptyRuns = function groupEmptyRuns(runs) {
var groups = runs.reduce(function (acc, run) {
if (!acc[run.start]) acc[run.start] = [];
acc[run.start].push(run);
return acc;
}, {});
return Object.values(groups);
};
var flattenEmptyRuns = function flattenEmptyRuns(runs) {
return groupEmptyRuns(runs).map(mergeRuns);
};
var flattenRegularRuns = function flattenRegularRuns(runs) {

@@ -54,3 +70,3 @@ var res = [];

stack.push(attributes);
attrs = R.merge(attrs, attributes);
attrs = Object.assign({}, attrs, attributes);
} else {

@@ -64,3 +80,3 @@ attrs = {};

} else {
attrs = R.merge(attrs, stack[j]);
attrs = Object.assign({}, attrs, stack[j]);
}

@@ -88,3 +104,9 @@ }

return R.compose(_sort.default, R.apply(R.useWith(R.concat, [flattenEmptyRuns, flattenRegularRuns])), R.partition(_isEmpty.default))(runs);
var emptyRuns = flattenEmptyRuns(runs.filter(function (run) {
return (0, _isEmpty.default)(run);
}));
var regularRuns = flattenRegularRuns(runs.filter(function (run) {
return !(0, _isEmpty.default)(run);
}));
return (0, _sort.default)(emptyRuns.concat(regularRuns));
};

@@ -91,0 +113,0 @@

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -16,4 +12,9 @@ * Get run font

*/
var getFont = R.pathOr(null, ['attributes', 'font']);
var getFont = function getFont(run) {
var _run$attributes;
return ((_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : _run$attributes.font) || null;
};
var _default = getFont;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _fns = require("@react-pdf/fns");

@@ -19,7 +17,9 @@ /**

var glyphIndexAt = function glyphIndexAt(index, run) {
return R.pathOr(index, ['glyphIndices', index])(run);
var _run$glyphIndices;
var result = run === null || run === void 0 ? void 0 : (_run$glyphIndices = run.glyphIndices) === null || _run$glyphIndices === void 0 ? void 0 : _run$glyphIndices[index];
return (0, _fns.isNil)(result) ? index : result;
};
var _default = R.curryN(2, glyphIndexAt);
var _default = glyphIndexAt;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _ascent = _interopRequireDefault(require("./ascent"));

@@ -25,4 +21,10 @@

*/
var height = R.either(R.path(['attributes', 'lineHeight']), R.compose(R.sum, R.juxt([_ascent.default, R.o(R.negate, _descent.default), _lineGap.default])));
var height = function height(run) {
var _run$attributes;
var lineHeight = (_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : _run$attributes.lineHeight;
return lineHeight || (0, _lineGap.default)(run) + (0, _ascent.default)(run) - (0, _descent.default)(run);
};
var _default = height;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -20,10 +16,12 @@ * Get string index at offset

var index = 0;
var glyphs = R.propOr([], 'glyphs', run);
var positions = R.propOr([], 'positions', run);
var glyphs = run.glyphs || [];
var positions = run.positions || [];
for (var i = 0; i < positions.length; i += 1) {
var _glyphs$i, _glyphs$i$codePoints;
var xAdvance = positions[i].xAdvance;
if (counter + xAdvance > offset) return index;
counter += xAdvance;
index += R.pathOr(0, [i, 'codePoints', 'length'], glyphs);
index += ((_glyphs$i = glyphs[i]) === null || _glyphs$i === void 0 ? void 0 : (_glyphs$i$codePoints = _glyphs$i.codePoints) === null || _glyphs$i$codePoints === void 0 ? void 0 : _glyphs$i$codePoints.length) || 0;
}

@@ -34,4 +32,3 @@

var _default = R.curryN(2, indexAtOffset);
var _default = indexAtOffset;
exports.default = _default;

@@ -5,11 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _copy = _interopRequireDefault(require("./copy"));
var _slice = _interopRequireDefault(require("./slice"));

@@ -36,3 +30,3 @@

var insertGlyph = function insertGlyph(index, glyph, run) {
if (!glyph) return (0, _copy.default)(run); // Split resolves ligature splitting in case new glyph breaks some
if (!glyph) return run; // Split resolves ligature splitting in case new glyph breaks some

@@ -59,4 +53,3 @@ var leadingRun = (0, _slice.default)(0, index, run);

var _default = R.curryN(3, insert);
var _default = insert;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -16,4 +12,7 @@ * Is run empty (start === end)

*/
var isEmpty = R.converge(R.equals, [R.prop('start'), R.prop('end')]);
var isEmpty = function isEmpty(run) {
return run.start === run.end;
};
var _default = isEmpty;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _isWhiteSpace = _interopRequireDefault(require("../glyph/isWhiteSpace"));

@@ -21,3 +17,10 @@

*/
var leadingPositions = R.converge(R.slice(0), [R.compose(R.length, R.takeWhile(_isWhiteSpace.default), R.propOr([], 'glyphs')), R.propOr([], 'positions')]);
var leadingPositions = function leadingPositions(run) {
var glyphs = run.glyphs || [];
var positions = run.positions || [];
var leadingWhitespaces = glyphs.findIndex(function (g) {
return !(0, _isWhiteSpace.default)(g);
});
return positions.slice(0, leadingWhitespaces);
};
/**

@@ -30,4 +33,11 @@ * Get run leading white space offset

var leadingOffset = R.compose(R.ifElse(R.isEmpty, R.always(0), R.compose(R.sum, R.map(R.propOr(0, 'xAdvance')))), leadingPositions);
var leadingOffset = function leadingOffset(run) {
var positions = leadingPositions(run);
return positions.reduce(function (acc, pos) {
return acc + (pos.xAdvance || 0);
}, 0);
};
var _default = leadingOffset;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -16,4 +12,7 @@ * Get run length

*/
var length = R.converge(R.subtract, [R.prop('end'), R.prop('start')]);
var length = function length(run) {
return run.end - run.start;
};
var _default = length;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _scale = _interopRequireDefault(require("./scale"));

@@ -21,4 +17,9 @@

*/
var lineGap = R.converge(R.multiply, [_scale.default, R.pathOr(0, ['attributes', 'font', 'lineGap'])]);
var lineGap = function lineGap(run) {
var _run$attributes, _run$attributes$font;
return (((_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : (_run$attributes$font = _run$attributes.font) === null || _run$attributes$font === void 0 ? void 0 : _run$attributes$font.lineGap) || 0) * (0, _scale.default)(run);
};
var _default = lineGap;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -24,8 +20,11 @@ * Get ligature offset by index

var offset = function offset(index, run) {
var value = R.pathOr(null, ['glyphIndices', index], run);
return R.compose(R.length, R.dropWhile(R.gt(value)), R.slice(0, index), R.propOr([], 'glyphIndices'))(run);
if (!run) return 0;
var glyphIndices = run.glyphIndices || [];
var value = glyphIndices[index];
return glyphIndices.slice(0, index).filter(function (i) {
return i === value;
}).length;
};
var _default = R.curryN(2, offset);
var _default = offset;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -17,9 +13,10 @@ * Omit attribute from run

var omit = function omit(value, run) {
return R.evolve({
attributes: R.dissoc(value)
})(run);
var attributes = Object.assign({}, run.attributes);
delete attributes[value];
return Object.assign({}, run, {
attributes: attributes
});
};
var _default = R.curryN(2, omit);
var _default = omit;
exports.default = _default;

@@ -5,11 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _copy = _interopRequireDefault(require("./copy"));
var _scale = _interopRequireDefault(require("./scale"));

@@ -34,11 +28,15 @@

var runScale = (0, _scale.default)(run);
var glyphLength = R.length(glyph.codePoints);
return R.evolve({
end: R.add(glyphLength),
glyphIndices: (0, _prepend.default)(glyphLength),
glyphs: R.prepend(glyph),
positions: R.prepend({
xAdvance: glyph.advanceWidth * runScale
})
})(run);
var glyphLength = glyph.codePoints.length;
var end = run.end + glyphLength;
var glyphIndices = (0, _prepend.default)(glyphLength, run.glyphIndices);
var glyphs = [glyph].concat(run.glyphs);
var positions = [{
xAdvance: glyph.advanceWidth * runScale
}].concat(run.positions);
return Object.assign({}, run, {
end: end,
glyphs: glyphs,
glyphIndices: glyphIndices,
positions: positions
});
};

@@ -55,3 +53,3 @@ /**

var prepend = function prepend(value, run) {
if (!value) return (0, _copy.default)(run);
if (!value) return run;
var font = (0, _getFont.default)(run);

@@ -62,4 +60,3 @@ var glyph = (0, _isNumber.default)(value) ? (0, _fromCodePoint.default)(value, font) : value;

var _default = R.curryN(2, prepend);
var _default = prepend;
exports.default = _default;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _isBetween = _interopRequireDefault(require("../utils/isBetween"));
/**

@@ -22,7 +14,9 @@ * Get run index that contains passed index

var runIndexAt = function runIndexAt(n, runs) {
return R.findIndex((0, _isBetween.default)(R.prop('start'), R.prop('end'), n))(runs);
if (!runs) return -1;
return runs.findIndex(function (run) {
return run.start <= n && n < run.end;
});
};
var _default = R.curryN(2, runIndexAt);
var _default = runIndexAt;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var unitsPerEm = ['font', 'unitsPerEm'];
/**

@@ -17,4 +12,10 @@ * Calculate run scale

*/
var calculateScale = function calculateScale(run) {
var _attributes$font;
var calculateScale = R.compose(R.ifElse(R.compose(R.not, R.isNil, R.path(unitsPerEm)), R.converge(R.divide, [R.propOr(12, 'fontSize'), R.path(unitsPerEm)]), R.always(0)), R.propOr({}, 'attributes'));
var attributes = run.attributes || {};
var fontSize = attributes.fontSize || 12;
var unitsPerEm = (_attributes$font = attributes.font) === null || _attributes$font === void 0 ? void 0 : _attributes$font.unitsPerEm;
return unitsPerEm ? fontSize / unitsPerEm : 0;
};
/**

@@ -27,4 +28,10 @@ * Get run scale

var scale = R.either(R.path(['attributes', 'scale']), calculateScale);
var scale = function scale(run) {
var _run$attributes;
return ((_run$attributes = run.attributes) === null || _run$attributes === void 0 ? void 0 : _run$attributes.scale) || calculateScale(run);
};
var _default = scale;
exports.default = _default;

@@ -5,9 +5,5 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _scale = _interopRequireDefault(require("./scale"));

@@ -34,10 +30,12 @@

var slice = function slice(start, end, run) {
var _run$glyphs, _run$glyphs2;
var runScale = (0, _scale.default)(run);
var font = (0, _getFont.default)(run); // Get glyph start and end indices
var glyphStartIndex = (0, _glyphIndexAt.default)(start, run);
var glyphEndIndex = (0, _glyphIndexAt.default)(end, run); // Get start and end glyph
var startIndex = (0, _glyphIndexAt.default)(start, run);
var endIndex = (0, _glyphIndexAt.default)(end, run); // Get start and end glyph
var startGlyph = R.path(['glyphs', glyphStartIndex], run);
var endGlyph = R.path(['glyphs', glyphEndIndex], run); // Get start ligature chunks (if any)
var startGlyph = (_run$glyphs = run.glyphs) === null || _run$glyphs === void 0 ? void 0 : _run$glyphs[startIndex];
var endGlyph = (_run$glyphs2 = run.glyphs) === null || _run$glyphs2 === void 0 ? void 0 : _run$glyphs2[endIndex]; // Get start ligature chunks (if any)

@@ -48,30 +46,26 @@ var startOffset = (0, _offset.default)(start, run);

var endOffset = (0, _offset.default)(end, run);
var endGlyphs = (0, _slice.default)(0, endOffset, font, endGlyph);
var sliceOffset = Math.min(1, startOffset);
return R.evolve({
start: R.add(start),
end: R.compose(R.apply(R.min), R.juxt([R.identity, // string.end
R.o(R.add(end), R.always(run.start)) // end + string.start
])),
glyphs: function glyphs(_glyphs) {
return R.flatten([startGlyphs, _glyphs.slice(glyphStartIndex + sliceOffset, glyphEndIndex), endGlyphs]);
},
positions: function positions(_positions) {
return R.flatten([startGlyphs.map(function (g) {
return {
xAdvance: g.advanceWidth * runScale
};
}), _positions.slice(glyphStartIndex + sliceOffset, glyphEndIndex), endGlyphs.map(function (g) {
return {
xAdvance: g.advanceWidth * runScale
};
})]);
},
glyphIndices: R.o(_normalize.default, R.slice(start, end)),
attributes: R.identity
})(run);
var endGlyphs = (0, _slice.default)(0, endOffset, font, endGlyph); // Compute new glyphs
var sliceStart = startIndex + Math.min(1, startOffset);
var glyphs = (run.glyphs || []).slice(sliceStart, endIndex); // Compute new positions
var glyphPosition = function glyphPosition(g) {
return {
xAdvance: g.advanceWidth * runScale
};
};
var startPositions = startGlyphs.map(glyphPosition);
var positions = (run.positions || []).slice(sliceStart, endIndex);
var endPositions = endGlyphs.map(glyphPosition);
return Object.assign({}, run, {
start: run.start + start,
end: Math.min(run.end, run.start + end),
glyphIndices: (0, _normalize.default)((run.glyphIndices || []).slice(start, end)),
glyphs: [startGlyphs, glyphs, endGlyphs].flat(),
positions: [startPositions, positions, endPositions].flat()
});
};
var _default = R.curryN(3, slice);
var _default = slice;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -16,8 +12,9 @@ * Sort runs in ascending order

*/
var sort = function sort(a, b) {
return a.start - b.start || a.end - b.end;
var sort = function sort(runs) {
return runs.sort(function (a, b) {
return a.start - b.start || a.end - b.end;
});
};
var _default = R.sort(sort);
var _default = sort;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
/**

@@ -18,10 +14,11 @@ * Subtract scalar to run

var subtract = function subtract(n, run) {
return R.evolve({
start: R.subtract(R.__, n),
end: R.subtract(R.__, n)
})(run);
var start = run.start - n;
var end = run.end - n;
return Object.assign({}, run, {
start: start,
end: end
});
};
var _default = R.curryN(2, subtract);
var _default = subtract;
exports.default = _default;

@@ -5,11 +5,10 @@ "use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var _isWhiteSpace = _interopRequireDefault(require("../glyph/isWhiteSpace"));
var reverse = function reverse(array) {
return [].concat(array).reverse();
};
/**

@@ -21,3 +20,12 @@ * Get white space trailing positions

*/
var trailingPositions = R.converge(R.slice(0), [R.compose(R.length, R.takeWhile(_isWhiteSpace.default), R.reverse, R.propOr([], 'glyphs')), R.compose(R.reverse, R.propOr([], 'positions'))]);
var trailingPositions = function trailingPositions(run) {
var glyphs = reverse(run.glyphs || []);
var positions = reverse(run.positions || []);
var leadingWhitespaces = glyphs.findIndex(function (g) {
return !(0, _isWhiteSpace.default)(g);
});
return positions.slice(0, leadingWhitespaces);
};
/**

@@ -30,4 +38,11 @@ * Get run trailing white space offset

var trailingOffset = R.compose(R.ifElse(R.isEmpty, R.always(0), R.compose(R.sum, R.map(R.propOr(0, 'xAdvance')))), trailingPositions);
var trailingOffset = function trailingOffset(run) {
var positions = trailingPositions(run);
return positions.reduce(function (acc, pos) {
return acc + (pos.xAdvance || 0);
}, 0);
};
var _default = trailingOffset;
exports.default = _default;
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var R = _interopRequireWildcard(require("ramda"));
var isNumber = function isNumber(value) {
return typeof value === 'number';
};
var isNumber = R.is(Number);
var _default = isNumber;
exports.default = _default;
{
"name": "@react-pdf/textkit",
"license": "MIT",
"version": "2.1.0",
"version": "3.0.0",
"description": "An advanced text layout framework",

@@ -26,6 +26,6 @@ "main": "./lib/index.js",

"@babel/runtime": "^7.16.4",
"@react-pdf/unicode-properties": "^2.5.0",
"hyphen": "^1.6.4",
"ramda": "^0.26.1"
"@react-pdf/fns": "1.0.0",
"@react-pdf/unicode-properties": "^2.6.0",
"hyphen": "^1.6.4"
}
}