49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _wrapText = _interopRequireDefault(require("./wrap-text"));
|
|
|
|
var _measureText = _interopRequireDefault(require("./measure-text"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
const calculateWrappedText = node => {
|
|
if (node.textContent && typeof node.parentNode.style.textWrap === 'string') {
|
|
const {
|
|
yogaNode
|
|
} = node;
|
|
const parentYogaNode = node.parentNode.yogaNode;
|
|
const maxWidth = parentYogaNode.getComputedWidth() - parentYogaNode.getComputedPadding() * 2;
|
|
const currentWidth = yogaNode.getComputedWidth();
|
|
|
|
if (currentWidth > maxWidth) {
|
|
const {
|
|
textWrap
|
|
} = node.parentNode.style;
|
|
const wrappedText = (0, _wrapText.default)(node.textContent, maxWidth, {
|
|
textWrap
|
|
});
|
|
const {
|
|
width,
|
|
height
|
|
} = (0, _measureText.default)(wrappedText);
|
|
yogaNode.setWidth(width);
|
|
yogaNode.setHeight(height);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (Array.isArray(node.childNodes) && node.childNodes.length > 0) {
|
|
for (const childNode of node.childNodes) {
|
|
calculateWrappedText(childNode);
|
|
}
|
|
}
|
|
};
|
|
|
|
var _default = calculateWrappedText;
|
|
exports.default = _default; |