UNPKG

docxml

Version:

TypeScript (component) library for building and parsing a DOCX file

45 lines (44 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tableConditionalPropertiesToNode = exports.tableConditionalPropertiesFromNode = 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"); const paragraph_properties_js_1 = require("./paragraph-properties.js"); const table_cell_properties_js_1 = require("./table-cell-properties.js"); const table_properties_js_1 = require("./table-properties.js"); const text_properties_js_1 = require("./text-properties.js"); function tableConditionalPropertiesFromNode(node) { const { pPr, rPr, tblPr, tcPr, ...rest } = (0, xquery_js_1.evaluateXPathToMap)(`map { "type": ./@${namespaces_js_1.QNS.w}type/string(), "pPr": ./${namespaces_js_1.QNS.w}pPr, "rPr": ./${namespaces_js_1.QNS.w}rPr, "tblPr": ./${namespaces_js_1.QNS.w}tblPr, "tcPr": ./${namespaces_js_1.QNS.w}tcPr }`, node); const properties = { ...rest, paragraph: pPr ? (0, paragraph_properties_js_1.paragraphPropertiesFromNode)(pPr) : null, text: rPr ? (0, text_properties_js_1.textPropertiesFromNode)(rPr) : null, table: tblPr ? (0, table_properties_js_1.tablePropertiesFromNode)(tblPr) : null, cell: tcPr ? (0, table_cell_properties_js_1.tableCellPropertiesFromNode)(tcPr) : null, }; return properties; } exports.tableConditionalPropertiesFromNode = tableConditionalPropertiesFromNode; function tableConditionalPropertiesToNode(tblpr) { return (0, dom_js_1.create)(`element ${namespaces_js_1.QNS.w}tblStylePr { attribute ${namespaces_js_1.QNS.w}type { $type }, $pPr, $rPr, $tblPr, $tcPr }`, { ...tblpr, pPr: tblpr.paragraph ? (0, paragraph_properties_js_1.paragraphPropertiesToNode)(tblpr.paragraph) : null, rPr: tblpr.text ? (0, text_properties_js_1.textPropertiesToNode)(tblpr.text) : null, tblPr: tblpr.table ? (0, table_properties_js_1.tablePropertiesToNode)(tblpr.table) : null, tcPr: tblpr.cell ? (0, table_cell_properties_js_1.tableCellPropertiesToNode)(tblpr.cell, false) : null, }); } exports.tableConditionalPropertiesToNode = tableConditionalPropertiesToNode;