UNPKG

docxml

Version:

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

115 lines (113 loc) 4.05 kB
"use strict"; // Import without assignment ensures Deno does not tree-shake this component. To avoid circular // definitions, components register themselves in a side-effect of their module. // // Add items to this list that would otherwise only be depended on as a type definition. Object.defineProperty(exports, "__esModule", { value: true }); exports.WatermarkText = void 0; const Component_js_1 = require("../classes/Component.js"); const components_js_1 = require("../utilities/components.js"); const dom_js_1 = require("../utilities/dom.js"); const length_js_1 = require("../utilities/length.js"); const namespaces_js_1 = require("../utilities/namespaces.js"); const xquery_js_1 = require("../utilities/xquery.js"); /** * */ class WatermarkText extends Component_js_1.Component { /** * Creates an XML DOM node for this component instance. * * * * */ toNode() { return (0, dom_js_1.create)(` element ${namespaces_js_1.QNS.w}p { element ${namespaces_js_1.QNS.w}r { element ${namespaces_js_1.QNS.w}pict { element ${namespaces_js_1.QNS.v}shape { attribute type { "#_x0000_t136" }, attribute style { concat( "position:absolute;", "margin-left:0;", "margin-top:0;", "width:", $boxWidth, "pt;", "height:", $boxHeight, "pt;", "z-index:-251651072;", "mso-wrap-edited:f;", "mso-width-percent:0;", "mso-height-percent:0;", "mso-position-horizontal:", $horizontalAlign, ";", "mso-position-horizontal-relative:page;", "mso-position-vertical:", $verticalAlign, ";", "mso-position-vertical-relative:page;", "mso-width-percent:0;", "mso-height-percent:0" ) }, attribute ${namespaces_js_1.QNS.o}allowincell { "f" }, attribute fillcolor { concat("#", $color) }, attribute stroked { "f" }, element ${namespaces_js_1.QNS.v}fill { attribute opacity { $opacity } }, element ${namespaces_js_1.QNS.v}textpath { attribute style { concat( "font-family:"",$font,"";", "font-size:", $minFontSize, "pt;", if ($isBold) then "font-weight:bold;" else (), if ($isItalic) then "font-style:italic" else () ) }, attribute string { $text } } } } } } `, { text: this.props.text, horizontalAlign: this.props.horizontalAlign || 'center', verticalAlign: this.props.verticalAlign || 'center', boxWidth: (this.props.boxWidth || (0, length_js_1.cm)(21.6)).pt, boxHeight: (this.props.boxHeight || (0, length_js_1.cm)(23.9)).pt, minFontSize: (this.props.minFontSize || (0, length_js_1.pt)(10)).pt, color: this.props.color || '000000', font: this.props.font || 'Arial', opacity: this.props.opacity === null || this.props.opacity === undefined ? '100%' : this.props.opacity * 100 + '%', isBold: !!this.props.isBold, isItalic: !!this.props.isItalic, }); } /** * Asserts whether or not a given XML node correlates with this component. */ static matchesNode(node) { // This will possibly have false positives on "real" Word content return (0, xquery_js_1.evaluateXPathToBoolean)('self::w:p[./w:r/w:pict]', node); } /** * Instantiate this component from the XML in an existing DOCX file. */ static fromNode(node) { const props = (0, xquery_js_1.evaluateXPathToMap)(`map { }`, node); return new WatermarkText(props); } } exports.WatermarkText = WatermarkText; Object.defineProperty(WatermarkText, "children", { enumerable: true, configurable: true, writable: true, value: [] }); Object.defineProperty(WatermarkText, "mixed", { enumerable: true, configurable: true, writable: true, value: false }); (0, components_js_1.registerComponent)(WatermarkText);