react-pdfmake
Version:
<a name="yarn"/>
71 lines • 2.63 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import isType from './is-type';
import { PDFTable, PDFTableRow, PDFColumns } from './elements';
import PDFDocument from './document';
var convert = function (element) {
if (!element) {
return {};
}
if (typeof element === 'string') {
return element;
}
var _a = element.props, children = _a.children, props = __rest(_a, ["children"]);
if (children) {
if (typeof children === 'string') {
props.text = children;
}
else if (Array.isArray(children)) {
props.children = children.map(convert);
}
else {
props.children = [convert(children)];
}
}
if (Object.keys(props).length === 1 && props.text) {
return props.text;
}
if (isType(element, PDFDocument)) {
var children_1 = props.children, rest = __rest(props, ["children"]);
return __assign(__assign({}, rest), { content: children_1 });
}
if (isType(element, PDFTable)) {
var children_2 = props.children, style = props.style, pageBreak = props.pageBreak, pageOrientation = props.pageOrientation, rest = __rest(props, ["children", "style", "pageBreak", "pageOrientation"]);
return {
style: style,
pageBreak: pageBreak,
pageOrientation: pageOrientation,
table: __assign(__assign({}, rest), { body: children_2 }),
};
}
if (isType(element, PDFColumns)) {
var children_3 = props.children, rest = __rest(props, ["children"]);
return __assign(__assign({}, rest), { columns: children_3 });
}
if (isType(element, PDFTableRow)) {
return props.children;
}
return props;
};
export default convert;
//# sourceMappingURL=convert.js.map