docxml
Version:
TypeScript (component) library for building and parsing a DOCX file
35 lines (34 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tableRowPropertiesToNode = exports.tableRowPropertiesFromNode = void 0;
const dom_js_1 = require("../utilities/dom.js");
const namespaces_js_1 = require("../utilities/namespaces.js");
const xquery_js_1 = require("../utilities/xquery.js");
function tableRowPropertiesFromNode(node) {
return node
? (0, xquery_js_1.evaluateXPathToMap)(`map {
"isHeaderRow": docxml:ct-on-off(./${namespaces_js_1.QNS.w}tblHeader),
"isUnsplittable": docxml:ct-on-off(./${namespaces_js_1.QNS.w}cantSplit),
"cellSpacing": docxml:length(${namespaces_js_1.QNS.w}tblCellSpacing[not(@${namespaces_js_1.QNS.w}type = 'nil')]/@${namespaces_js_1.QNS.w}w, 'twip')
}`, node)
: {};
}
exports.tableRowPropertiesFromNode = tableRowPropertiesFromNode;
function tableRowPropertiesToNode(tcpr = {}) {
if (!Object.keys(tcpr).length) {
return null;
}
return (0, dom_js_1.create)(`element ${namespaces_js_1.QNS.w}trPr {
if ($isHeaderRow) then element ${namespaces_js_1.QNS.w}tblHeader {} else (),
if ($isUnsplittable) then element ${namespaces_js_1.QNS.w}cantSplit {} else (),
if (exists($cellSpacing)) then element ${namespaces_js_1.QNS.w}tblCellSpacing {
attribute ${namespaces_js_1.QNS.w}w { round($cellSpacing('twip')) },
attribute ${namespaces_js_1.QNS.w}type { "dxa" }
} else ()
}`, {
isHeaderRow: tcpr.isHeaderRow || false,
isUnsplittable: tcpr.isUnsplittable || false,
cellSpacing: tcpr.cellSpacing || null,
});
}
exports.tableRowPropertiesToNode = tableRowPropertiesToNode;