UNPKG

pdfjs-dist

Version:

Generic build of Mozilla's PDF.js library.

1,602 lines (1,371 loc) 113 kB
/** * @licstart The following is the entire license notice for the * Javascript code in this page * * Copyright 2021 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @licend The above is the entire license notice for the * Javascript code in this page */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Value = exports.Text = exports.TemplateNamespace = exports.Template = exports.SetProperty = exports.Items = exports.Field = exports.BindItems = void 0; var _xfa_object = require("./xfa_object.js"); var _namespaces = require("./namespaces.js"); var _utils = require("./utils.js"); var _html_utils = require("./html_utils.js"); var _util = require("../../shared/util.js"); const TEMPLATE_NS_ID = _namespaces.NamespaceIds.template.id; function _setValue(templateNode, value) { if (!templateNode.value) { const nodeValue = new Value({}); templateNode[_xfa_object.$appendChild](nodeValue); templateNode.value = nodeValue; } templateNode.value[_xfa_object.$setValue](value); } class AppearanceFilter extends _xfa_object.StringObject { constructor(attributes) { super(TEMPLATE_NS_ID, "appearanceFilter"); this.id = attributes.id || ""; this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } } class Arc extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "arc", true); this.circular = (0, _utils.getInteger)({ data: attributes.circular, defaultValue: 0, validate: x => x === 1 }); this.hand = (0, _utils.getStringOption)(attributes.hand, ["even", "left", "right"]); this.id = attributes.id || ""; this.startAngle = (0, _utils.getFloat)({ data: attributes.startAngle, defaultValue: 0, validate: x => true }); this.sweepAngle = (0, _utils.getFloat)({ data: attributes.sweepAngle, defaultValue: 360, validate: x => true }); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.edge = null; this.fill = null; } } class Area extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "area", true); this.colSpan = (0, _utils.getInteger)({ data: attributes.colSpan, defaultValue: 1, validate: n => n >= 1 }); this.id = attributes.id || ""; this.name = attributes.name || ""; this.relevant = (0, _utils.getRelevant)(attributes.relevant); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.x = (0, _utils.getMeasurement)(attributes.x, "0pt"); this.y = (0, _utils.getMeasurement)(attributes.y, "0pt"); this.desc = null; this.extras = null; this.area = new _xfa_object.XFAObjectArray(); this.draw = new _xfa_object.XFAObjectArray(); this.exObject = new _xfa_object.XFAObjectArray(); this.exclGroup = new _xfa_object.XFAObjectArray(); this.field = new _xfa_object.XFAObjectArray(); this.subform = new _xfa_object.XFAObjectArray(); this.subformSet = new _xfa_object.XFAObjectArray(); } [_xfa_object.$isTransparent]() { return true; } } class Assist extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "assist", true); this.id = attributes.id || ""; this.role = attributes.role || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.speak = null; this.toolTip = null; } } class Barcode extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "barcode", true); this.charEncoding = (0, _utils.getKeyword)({ data: attributes.charEncoding ? attributes.charEncoding.toLowerCase() : "", defaultValue: "", validate: k => ["utf-8", "big-five", "fontspecific", "gbk", "gb-18030", "gb-2312", "ksc-5601", "none", "shift-jis", "ucs-2", "utf-16"].includes(k) || k.match(/iso-8859-[0-9]{2}/) }); this.checksum = (0, _utils.getStringOption)(attributes.checksum, ["none", "1mod10", "1mod10_1mod11", "2mod10", "auto"]); this.dataColumnCount = (0, _utils.getInteger)({ data: attributes.dataColumnCount, defaultValue: -1, validate: x => x >= 0 }); this.dataLength = (0, _utils.getInteger)({ data: attributes.dataLength, defaultValue: -1, validate: x => x >= 0 }); this.dataPrep = (0, _utils.getStringOption)(attributes.dataPrep, ["none", "flateCompress"]); this.dataRowCount = (0, _utils.getInteger)({ data: attributes.dataRowCount, defaultValue: -1, validate: x => x >= 0 }); this.endChar = attributes.endChar || ""; this.errorCorrectionLevel = (0, _utils.getInteger)({ data: attributes.errorCorrectionLevel, defaultValue: -1, validate: x => x >= 0 && x <= 8 }); this.id = attributes.id || ""; this.moduleHeight = (0, _utils.getMeasurement)(attributes.moduleHeight, "5mm"); this.moduleWidth = (0, _utils.getMeasurement)(attributes.moduleWidth, "0.25mm"); this.printCheckDigit = (0, _utils.getInteger)({ data: attributes.printCheckDigit, defaultValue: 0, validate: x => x === 1 }); this.rowColumnRatio = (0, _utils.getRatio)(attributes.rowColumnRatio); this.startChar = attributes.startChar || ""; this.textLocation = (0, _utils.getStringOption)(attributes.textLocation, ["below", "above", "aboveEmbedded", "belowEmbedded", "none"]); this.truncate = (0, _utils.getInteger)({ data: attributes.truncate, defaultValue: 0, validate: x => x === 1 }); this.type = (0, _utils.getStringOption)(attributes.type ? attributes.type.toLowerCase() : "", ["aztec", "codabar", "code2of5industrial", "code2of5interleaved", "code2of5matrix", "code2of5standard", "code3of9", "code3of9extended", "code11", "code49", "code93", "code128", "code128a", "code128b", "code128c", "code128sscc", "datamatrix", "ean8", "ean8add2", "ean8add5", "ean13", "ean13add2", "ean13add5", "ean13pwcd", "fim", "logmars", "maxicode", "msi", "pdf417", "pdf417macro", "plessey", "postauscust2", "postauscust3", "postausreplypaid", "postausstandard", "postukrm4scc", "postusdpbc", "postusimb", "postusstandard", "postus5zip", "qrcode", "rfid", "rss14", "rss14expanded", "rss14limited", "rss14stacked", "rss14stackedomni", "rss14truncated", "telepen", "ucc128", "ucc128random", "ucc128sscc", "upca", "upcaadd2", "upcaadd5", "upcapwcd", "upce", "upceadd2", "upceadd5", "upcean2", "upcean5", "upsmaxicode"]); this.upsMode = (0, _utils.getStringOption)(attributes.upsMode, ["usCarrier", "internationalCarrier", "secureSymbol", "standardSymbol"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.wideNarrowRatio = (0, _utils.getRatio)(attributes.wideNarrowRatio); this.encrypt = null; this.extras = null; } } class Bind extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "bind", true); this.match = (0, _utils.getStringOption)(attributes.match, ["once", "dataRef", "global", "none"]); this.ref = attributes.ref || ""; this.picture = null; } } class BindItems extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "bindItems"); this.connection = attributes.connection || ""; this.labelRef = attributes.labelRef || ""; this.ref = attributes.ref || ""; this.valueRef = attributes.valueRef || ""; } } exports.BindItems = BindItems; class Bookend extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "bookend"); this.id = attributes.id || ""; this.leader = attributes.leader || ""; this.trailer = attributes.trailer || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } } class BooleanElement extends _xfa_object.Option01 { constructor(attributes) { super(TEMPLATE_NS_ID, "boolean"); this.id = attributes.id || ""; this.name = attributes.name || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } [_xfa_object.$toHTML]() { return this[_xfa_object.$content] === 1; } } class Border extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "border", true); this.break = (0, _utils.getStringOption)(attributes.break, ["close", "open"]); this.hand = (0, _utils.getStringOption)(attributes.hand, ["even", "left", "right"]); this.id = attributes.id || ""; this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); this.relevant = (0, _utils.getRelevant)(attributes.relevant); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.corner = new _xfa_object.XFAObjectArray(4); this.edge = new _xfa_object.XFAObjectArray(4); this.extras = null; this.fill = null; this.margin = null; } [_xfa_object.$toStyle](widths, margins) { const edgeStyles = this.edge.children.map(node => node[_xfa_object.$toStyle]()); const cornerStyles = this.edge.children.map(node => node[_xfa_object.$toStyle]()); let style; if (this.margin) { style = this.margin[_xfa_object.$toStyle](); if (margins) { margins.push(this.margin.topInset, this.margin.rightInset, this.margin.bottomInset, this.margin.leftInset); } } else { style = Object.create(null); if (margins) { margins.push(0, 0, 0, 0); } } if (this.fill) { Object.assign(style, this.fill[_xfa_object.$toStyle]()); } if (edgeStyles.length > 0) { if (widths) { this.edge.children.forEach(node => widths.push(node.thickness)); if (widths.length < 4) { const last = widths[widths.length - 1]; for (let i = widths.length; i < 4; i++) { widths.push(last); } } } if (edgeStyles.length === 2 || edgeStyles.length === 3) { const last = edgeStyles[edgeStyles.length - 1]; for (let i = edgeStyles.length; i < 4; i++) { edgeStyles.push(last); } } style.borderWidth = edgeStyles.map(s => s.width).join(" "); style.borderColor = edgeStyles.map(s => s.color).join(" "); style.borderStyle = edgeStyles.map(s => s.style).join(" "); } else { if (widths) { widths.push(0, 0, 0, 0); } } if (cornerStyles.length > 0) { if (cornerStyles.length === 2 || cornerStyles.length === 3) { const last = cornerStyles[cornerStyles.length - 1]; for (let i = cornerStyles.length; i < 4; i++) { cornerStyles.push(last); } } style.borderRadius = cornerStyles.map(s => s.radius).join(" "); } switch (this.presence) { case "invisible": case "hidden": style.borderStyle = ""; break; case "inactive": style.borderStyle = "none"; break; } return style; } } class Break extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "break", true); this.after = (0, _utils.getStringOption)(attributes.after, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]); this.afterTarget = attributes.afterTarget || ""; this.before = (0, _utils.getStringOption)(attributes.before, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]); this.beforeTarget = attributes.beforeTarget || ""; this.bookendLeader = attributes.bookendLeader || ""; this.bookendTrailer = attributes.bookendTrailer || ""; this.id = attributes.id || ""; this.overflowLeader = attributes.overflowLeader || ""; this.overflowTarget = attributes.overflowTarget || ""; this.overflowTrailer = attributes.overflowTrailer || ""; this.startNew = (0, _utils.getInteger)({ data: attributes.startNew, defaultValue: 0, validate: x => x === 1 }); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.extras = null; } } class BreakAfter extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "breakAfter", true); this.id = attributes.id || ""; this.leader = attributes.leader || ""; this.startNew = (0, _utils.getInteger)({ data: attributes.startNew, defaultValue: 0, validate: x => x === 1 }); this.target = attributes.target || ""; this.targetType = (0, _utils.getStringOption)(attributes.targetType, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]); this.trailer = attributes.trailer || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.script = null; } } class BreakBefore extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "breakBefore", true); this.id = attributes.id || ""; this.leader = attributes.leader || ""; this.startNew = (0, _utils.getInteger)({ data: attributes.startNew, defaultValue: 0, validate: x => x === 1 }); this.target = attributes.target || ""; this.targetType = (0, _utils.getStringOption)(attributes.targetType, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]); this.trailer = attributes.trailer || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.script = null; } } class Button extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "button", true); this.highlight = (0, _utils.getStringOption)(attributes.highlight, ["inverted", "none", "outline", "push"]); this.id = attributes.id || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.extras = null; } [_xfa_object.$toHTML]() { return { name: "button", attributes: { class: "xfaButton", style: {} } }; } } class Calculate extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "calculate", true); this.id = attributes.id || ""; this.override = (0, _utils.getStringOption)(attributes.override, ["disabled", "error", "ignore", "warning"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.extras = null; this.message = null; this.script = null; } } class Caption extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "caption", true); this.id = attributes.id || ""; this.placement = (0, _utils.getStringOption)(attributes.placement, ["left", "bottom", "inline", "right", "top"]); this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); this.reserve = (0, _utils.getMeasurement)(attributes.reserve); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.extras = null; this.font = null; this.margin = null; this.para = null; this.value = null; } [_xfa_object.$setValue](value) { _setValue(this, value); } [_xfa_object.$toHTML]() { if (!this.value) { return null; } const value = this.value[_xfa_object.$toHTML](); if (!value) { return null; } const children = []; if (typeof value === "string") { children.push({ name: "#text", value }); } else { children.push(value); } const style = (0, _html_utils.toStyle)(this, "font", "margin", "para", "visibility"); switch (this.placement) { case "left": case "right": style.minWidth = (0, _html_utils.measureToString)(this.reserve); break; case "top": case "bottom": style.minHeight = (0, _html_utils.measureToString)(this.reserve); break; } return { name: "div", attributes: { style }, children }; } } class Certificate extends _xfa_object.StringObject { constructor(attributes) { super(TEMPLATE_NS_ID, "certificate"); this.id = attributes.id || ""; this.name = attributes.name || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } } class Certificates extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "certificates", true); this.credentialServerPolicy = (0, _utils.getStringOption)(attributes.credentialServerPolicy, ["optional", "required"]); this.id = attributes.id || ""; this.url = attributes.url || ""; this.urlPolicy = attributes.urlPolicy || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.encryption = null; this.issuers = null; this.keyUsage = null; this.oids = null; this.signing = null; this.subjectDNs = null; } } class CheckButton extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "checkButton", true); this.id = attributes.id || ""; this.mark = (0, _utils.getStringOption)(attributes.mark, ["default", "check", "circle", "cross", "diamond", "square", "star"]); this.shape = (0, _utils.getStringOption)(attributes.shape, ["square", "round"]); this.size = (0, _utils.getMeasurement)(attributes.size, "10pt"); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.border = null; this.extras = null; this.margin = null; } [_xfa_object.$toHTML]() { const style = (0, _html_utils.toStyle)(this, "border", "margin"); const size = (0, _html_utils.measureToString)(this.size); style.width = style.height = size; let mark, radius; if (this.shape === "square") { mark = "■"; radius = "10%"; } else { mark = "●"; radius = "50%"; } if (!style.borderRadius) { style.borderRadius = radius; } if (this.mark !== "default") { switch (this.mark) { case "check": mark = "✓"; break; case "circle": mark = "●"; break; case "cross": mark = "✕"; break; case "diamond": mark = "♦"; break; case "square": mark = "■"; break; case "star": mark = "★"; break; } } if (size !== "10px") { style.fontSize = size; style.lineHeight = size; style.width = size; style.height = size; } return { name: "label", attributes: { class: "xfaLabel" }, children: [{ name: "input", attributes: { class: "xfaCheckbox", type: "checkbox" } }, { name: "span", attributes: { class: "xfaCheckboxMark", mark, style } }] }; } } class ChoiceList extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "choiceList", true); this.commitOn = (0, _utils.getStringOption)(attributes.commitOn, ["select", "exit"]); this.id = attributes.id || ""; this.open = (0, _utils.getStringOption)(attributes.open, ["userControl", "always", "multiSelect", "onEntry"]); this.textEntry = (0, _utils.getInteger)({ data: attributes.textEntry, defaultValue: 0, validate: x => x === 1 }); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.border = null; this.extras = null; this.margin = null; } [_xfa_object.$toHTML]() { const style = (0, _html_utils.toStyle)(this, "border", "margin"); return { name: "label", attributes: { class: "xfaLabel" }, children: [{ name: "select", attributes: { class: "xfaSxelect", multiple: this.open === "multiSelect", style } }] }; } } class Color extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "color", true); this.cSpace = (0, _utils.getStringOption)(attributes.cSpace, ["SRGB"]); this.id = attributes.id || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.value = (0, _utils.getColor)(attributes.value); this.extras = null; } [_xfa_object.$hasSettableValue]() { return false; } [_xfa_object.$toStyle]() { return _util.Util.makeHexColor(this.value.r, this.value.g, this.value.b); } } class Comb extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "comb"); this.id = attributes.id || ""; this.numberOfCells = (0, _utils.getInteger)({ data: attributes.numberOfCells, defaultValue: 0, validate: x => x >= 0 }); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } } class Connect extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "connect", true); this.connection = attributes.connection || ""; this.id = attributes.id || ""; this.ref = attributes.ref || ""; this.usage = (0, _utils.getStringOption)(attributes.usage, ["exportAndImport", "exportOnly", "importOnly"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.picture = null; } } class ContentArea extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "contentArea", true); this.h = (0, _utils.getMeasurement)(attributes.h); this.id = attributes.id || ""; this.name = attributes.name || ""; this.relevant = (0, _utils.getRelevant)(attributes.relevant); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.w = (0, _utils.getMeasurement)(attributes.w); this.x = (0, _utils.getMeasurement)(attributes.x, "0pt"); this.y = (0, _utils.getMeasurement)(attributes.y, "0pt"); this.desc = null; this.extras = null; } [_xfa_object.$toHTML]() { const left = (0, _html_utils.measureToString)(this.x); const top = (0, _html_utils.measureToString)(this.y); const style = { position: "absolute", left, top, width: (0, _html_utils.measureToString)(this.w), height: (0, _html_utils.measureToString)(this.h) }; return { name: "div", children: [], attributes: { style, class: "xfaContentarea", id: this[_xfa_object.$uid] } }; } } class Corner extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "corner", true); this.id = attributes.id || ""; this.inverted = (0, _utils.getInteger)({ data: attributes.inverted, defaultValue: 0, validate: x => x === 1 }); this.join = (0, _utils.getStringOption)(attributes.join, ["square", "round"]); this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); this.radius = (0, _utils.getMeasurement)(attributes.radius); this.stroke = (0, _utils.getStringOption)(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]); this.thickness = (0, _utils.getMeasurement)(attributes.thickness, "0.5pt"); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.color = null; this.extras = null; } [_xfa_object.$toStyle]() { const style = (0, _html_utils.toStyle)(this, "visibility"); style.radius = (0, _html_utils.measureToString)(this.radius); return style; } } class DateElement extends _xfa_object.ContentObject { constructor(attributes) { super(TEMPLATE_NS_ID, "date"); this.id = attributes.id || ""; this.name = attributes.name || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } [_xfa_object.$finalize]() { this[_xfa_object.$content] = new Date(this[_xfa_object.$content].trim()); } [_xfa_object.$toHTML]() { return this[_xfa_object.$content].toString(); } } class DateTime extends _xfa_object.ContentObject { constructor(attributes) { super(TEMPLATE_NS_ID, "dateTime"); this.id = attributes.id || ""; this.name = attributes.name || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } [_xfa_object.$finalize]() { this[_xfa_object.$content] = new Date(this[_xfa_object.$content].trim()); } [_xfa_object.$toHTML]() { return this[_xfa_object.$content].toString(); } } class DateTimeEdit extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "dateTimeEdit", true); this.hScrollPolicy = (0, _utils.getStringOption)(attributes.hScrollPolicy, ["auto", "off", "on"]); this.id = attributes.id || ""; this.picker = (0, _utils.getStringOption)(attributes.picker, ["host", "none"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.border = null; this.comb = null; this.extras = null; this.margin = null; } [_xfa_object.$toHTML]() { const style = (0, _html_utils.toStyle)(this, "border", "font", "margin"); const html = { name: "input", attributes: { type: "text", class: "xfaTextfield", style } }; return { name: "label", attributes: { class: "xfaLabel" }, children: [html] }; } } class Decimal extends _xfa_object.ContentObject { constructor(attributes) { super(TEMPLATE_NS_ID, "decimal"); this.fracDigits = (0, _utils.getInteger)({ data: attributes.fracDigits, defaultValue: 2, validate: x => true }); this.id = attributes.id || ""; this.leadDigits = (0, _utils.getInteger)({ data: attributes.leadDigits, defaultValue: -1, validate: x => true }); this.name = attributes.name || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } [_xfa_object.$finalize]() { const number = parseFloat(this[_xfa_object.$content].trim()); this[_xfa_object.$content] = isNaN(number) ? null : number; } [_xfa_object.$toHTML]() { return this[_xfa_object.$content] !== null ? this[_xfa_object.$content].toString() : ""; } } class DefaultUi extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "defaultUi", true); this.id = attributes.id || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.extras = null; } } class Desc extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "desc", true); this.id = attributes.id || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.boolean = new _xfa_object.XFAObjectArray(); this.date = new _xfa_object.XFAObjectArray(); this.dateTime = new _xfa_object.XFAObjectArray(); this.decimal = new _xfa_object.XFAObjectArray(); this.exData = new _xfa_object.XFAObjectArray(); this.float = new _xfa_object.XFAObjectArray(); this.image = new _xfa_object.XFAObjectArray(); this.integer = new _xfa_object.XFAObjectArray(); this.text = new _xfa_object.XFAObjectArray(); this.time = new _xfa_object.XFAObjectArray(); } } class DigestMethod extends _xfa_object.OptionObject { constructor(attributes) { super(TEMPLATE_NS_ID, "digestMethod", ["", "SHA1", "SHA256", "SHA512", "RIPEMD160"]); this.id = attributes.id || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } } class DigestMethods extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "digestMethods", true); this.id = attributes.id || ""; this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.digestMethod = new _xfa_object.XFAObjectArray(); } } class Draw extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "draw", true); this.anchorType = (0, _utils.getStringOption)(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]); this.colSpan = (0, _utils.getInteger)({ data: attributes.colSpan, defaultValue: 1, validate: x => x >= 1 }); this.h = attributes.h ? (0, _utils.getMeasurement)(attributes.h) : ""; this.hAlign = (0, _utils.getStringOption)(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]); this.id = attributes.id || ""; this.locale = attributes.locale || ""; this.maxH = (0, _utils.getMeasurement)(attributes.maxH, "0pt"); this.maxW = (0, _utils.getMeasurement)(attributes.maxW, "0pt"); this.minH = (0, _utils.getMeasurement)(attributes.minH, "0pt"); this.minW = (0, _utils.getMeasurement)(attributes.minW, "0pt"); this.name = attributes.name || ""; this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); this.relevant = (0, _utils.getRelevant)(attributes.relevant); this.rotate = (0, _utils.getInteger)({ data: attributes.rotate, defaultValue: 0, validate: x => x % 90 === 0 }); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.w = attributes.w ? (0, _utils.getMeasurement)(attributes.w) : ""; this.x = (0, _utils.getMeasurement)(attributes.x, "0pt"); this.y = (0, _utils.getMeasurement)(attributes.y, "0pt"); this.assist = null; this.border = null; this.caption = null; this.desc = null; this.extras = null; this.font = null; this.keep = null; this.margin = null; this.para = null; this.traversal = null; this.ui = null; this.value = null; this.setProperty = new _xfa_object.XFAObjectArray(); } [_xfa_object.$setValue](value) { _setValue(this, value); } [_xfa_object.$toHTML]() { if (!this.value) { return null; } const style = (0, _html_utils.toStyle)(this, "font", "dimensions", "position", "presence", "rotate", "anchorType"); const clazz = ["xfaDraw"]; if (this.font) { clazz.push("xfaFont"); } const attributes = { style, id: this[_xfa_object.$uid], class: clazz.join(" ") }; if (this.name) { attributes.xfaName = this.name; } return { name: "div", attributes, children: [] }; } } class Edge extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "edge", true); this.cap = (0, _utils.getStringOption)(attributes.cap, ["square", "butt", "round"]); this.id = attributes.id || ""; this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); this.stroke = (0, _utils.getStringOption)(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]); this.thickness = (0, _utils.getMeasurement)(attributes.thickness, "0.5pt"); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.color = null; this.extras = null; } [_xfa_object.$toStyle]() { const style = (0, _html_utils.toStyle)(this, "visibility"); Object.assign(style, { linecap: this.cap, width: (0, _html_utils.measureToString)(this.thickness), color: this.color ? this.color[_xfa_object.$toHTML]() : "#000000", style: "" }); if (this.presence !== "visible") { style.style = "none"; } else { switch (this.stroke) { case "solid": style.style = "solid"; break; case "dashDot": style.style = "dashed"; break; case "dashDotDot": style.style = "dashed"; break; case "dashed": style.style = "dashed"; break; case "dotted": style.style = "dotted"; break; case "embossed": style.style = "ridge"; break; case "etched": style.style = "groove"; break; case "lowered": style.style = "inset"; break; case "raised": style.style = "outset"; break; } } return style; } } class Encoding extends _xfa_object.OptionObject { constructor(attributes) { super(TEMPLATE_NS_ID, "encoding", ["adbe.x509.rsa_sha1", "adbe.pkcs7.detached", "adbe.pkcs7.sha1"]); this.id = attributes.id || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } } class Encodings extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "encodings", true); this.id = attributes.id || ""; this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.encoding = new _xfa_object.XFAObjectArray(); } } class Encrypt extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "encrypt", true); this.id = attributes.id || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.certificate = null; } } class EncryptData extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "encryptData", true); this.id = attributes.id || ""; this.operation = (0, _utils.getStringOption)(attributes.operation, ["encrypt", "decrypt"]); this.target = attributes.target || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.filter = null; this.manifest = null; } } class Encryption extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "encryption", true); this.id = attributes.id || ""; this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.certificate = new _xfa_object.XFAObjectArray(); } } class EncryptionMethod extends _xfa_object.OptionObject { constructor(attributes) { super(TEMPLATE_NS_ID, "encryptionMethod", ["", "AES256-CBC", "TRIPLEDES-CBC", "AES128-CBC", "AES192-CBC"]); this.id = attributes.id || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } } class EncryptionMethods extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "encryptionMethods", true); this.id = attributes.id || ""; this.type = (0, _utils.getStringOption)(attributes.type, ["optional", "required"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.encryptionMethod = new _xfa_object.XFAObjectArray(); } } class Event extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "event", true); this.activity = (0, _utils.getStringOption)(attributes.activity, ["click", "change", "docClose", "docReady", "enter", "exit", "full", "indexChange", "initialize", "mouseDown", "mouseEnter", "mouseExit", "mouseUp", "postExecute", "postOpen", "postPrint", "postSave", "postSign", "postSubmit", "preExecute", "preOpen", "prePrint", "preSave", "preSign", "preSubmit", "ready", "validationState"]); this.id = attributes.id || ""; this.listen = (0, _utils.getStringOption)(attributes.listen, ["refOnly", "refAndDescendents"]); this.name = attributes.name || ""; this.ref = attributes.ref || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.extras = null; this.encryptData = null; this.execute = null; this.script = null; this.signData = null; this.submit = null; } } class ExData extends _xfa_object.ContentObject { constructor(attributes) { super(TEMPLATE_NS_ID, "exData"); this.contentType = attributes.contentType || ""; this.href = attributes.href || ""; this.id = attributes.id || ""; this.maxLength = (0, _utils.getInteger)({ data: attributes.maxLength, defaultValue: -1, validate: x => x >= -1 }); this.name = attributes.name || ""; this.rid = attributes.rid || ""; this.transferEncoding = (0, _utils.getStringOption)(attributes.transferEncoding, ["none", "base64", "package"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } [_xfa_object.$onChild](child) { if (this.contentType === "text/html" && child[_xfa_object.$namespaceId] === _namespaces.NamespaceIds.xhtml.id) { this[_xfa_object.$content] = child; return true; } if (this.contentType === "text/xml") { this[_xfa_object.$content] = child; return true; } return false; } } class ExObject extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "exObject", true); this.archive = attributes.archive || ""; this.classId = attributes.classId || ""; this.codeBase = attributes.codeBase || ""; this.codeType = attributes.codeType || ""; this.id = attributes.id || ""; this.name = attributes.name || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.extras = null; this.boolean = new _xfa_object.XFAObjectArray(); this.date = new _xfa_object.XFAObjectArray(); this.dateTime = new _xfa_object.XFAObjectArray(); this.decimal = new _xfa_object.XFAObjectArray(); this.exData = new _xfa_object.XFAObjectArray(); this.exObject = new _xfa_object.XFAObjectArray(); this.float = new _xfa_object.XFAObjectArray(); this.image = new _xfa_object.XFAObjectArray(); this.integer = new _xfa_object.XFAObjectArray(); this.text = new _xfa_object.XFAObjectArray(); this.time = new _xfa_object.XFAObjectArray(); } } class ExclGroup extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "exclGroup", true); this.access = (0, _utils.getStringOption)(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]); this.accessKey = attributes.accessKey || ""; this.anchorType = (0, _utils.getStringOption)(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]); this.colSpan = (0, _utils.getInteger)({ data: attributes.colSpan, defaultValue: 1, validate: x => x >= 1 }); this.h = attributes.h ? (0, _utils.getMeasurement)(attributes.h) : ""; this.hAlign = (0, _utils.getStringOption)(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]); this.id = attributes.id || ""; this.layout = (0, _utils.getStringOption)(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]); this.maxH = (0, _utils.getMeasurement)(attributes.maxH, "0pt"); this.maxW = (0, _utils.getMeasurement)(attributes.maxW, "0pt"); this.minH = (0, _utils.getMeasurement)(attributes.minH, "0pt"); this.minW = (0, _utils.getMeasurement)(attributes.minW, "0pt"); this.name = attributes.name || ""; this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); this.relevant = (0, _utils.getRelevant)(attributes.relevant); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.w = attributes.w ? (0, _utils.getMeasurement)(attributes.w) : ""; this.x = (0, _utils.getMeasurement)(attributes.x, "0pt"); this.y = (0, _utils.getMeasurement)(attributes.y, "0pt"); this.assist = null; this.bind = null; this.border = null; this.calculate = null; this.caption = null; this.desc = null; this.extras = null; this.margin = null; this.para = null; this.traversal = null; this.validate = null; this.connect = new _xfa_object.XFAObjectArray(); this.event = new _xfa_object.XFAObjectArray(); this.field = new _xfa_object.XFAObjectArray(); this.setProperty = new _xfa_object.XFAObjectArray(); } [_xfa_object.$hasSettableValue]() { return true; } [_xfa_object.$setValue](value) { for (const field of this.field.children) { if (!field.value) { const nodeValue = new Value({}); field[_xfa_object.$appendChild](nodeValue); field.value = nodeValue; } const nodeBoolean = new BooleanElement({}); nodeBoolean[_xfa_object.$content] = 0; for (const item of field.items.children) { if (item[_xfa_object.$hasItem](value)) { nodeBoolean[_xfa_object.$content] = 1; break; } } field.value[_xfa_object.$setValue](nodeBoolean); } } [_xfa_object.$toHTML]() { if (!this.value) { return null; } const style = (0, _html_utils.toStyle)(this, "dimensions", "position", "anchorType"); const attributes = { style, id: this[_xfa_object.$uid], class: "xfaExclgroup" }; const children = this[_xfa_object.$childrenToHTML]({ filter: new Set(["field"]), include: true }); return { name: "div", attributes, children }; } } class Execute extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "execute"); this.connection = attributes.connection || ""; this.executeType = (0, _utils.getStringOption)(attributes.executeType, ["import", "remerge"]); this.id = attributes.id || ""; this.runAt = (0, _utils.getStringOption)(attributes.runAt, ["client", "both", "server"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; } } class Extras extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "extras", true); this.id = attributes.id || ""; this.name = attributes.name || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.boolean = new _xfa_object.XFAObjectArray(); this.date = new _xfa_object.XFAObjectArray(); this.dateTime = new _xfa_object.XFAObjectArray(); this.decimal = new _xfa_object.XFAObjectArray(); this.exData = new _xfa_object.XFAObjectArray(); this.extras = new _xfa_object.XFAObjectArray(); this.float = new _xfa_object.XFAObjectArray(); this.image = new _xfa_object.XFAObjectArray(); this.integer = new _xfa_object.XFAObjectArray(); this.text = new _xfa_object.XFAObjectArray(); this.time = new _xfa_object.XFAObjectArray(); } } class Field extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "field", true); this.access = (0, _utils.getStringOption)(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]); this.accessKey = attributes.accessKey || ""; this.anchorType = (0, _utils.getStringOption)(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]); this.colSpan = (0, _utils.getInteger)({ data: attributes.colSpan, defaultValue: 1, validate: x => x >= 1 }); this.h = attributes.h ? (0, _utils.getMeasurement)(attributes.h) : ""; this.hAlign = (0, _utils.getStringOption)(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]); this.id = attributes.id || ""; this.locale = attributes.locale || ""; this.maxH = (0, _utils.getMeasurement)(attributes.maxH, "0pt"); this.maxW = (0, _utils.getMeasurement)(attributes.maxW, "0pt"); this.minH = (0, _utils.getMeasurement)(attributes.minH, "0pt"); this.minW = (0, _utils.getMeasurement)(attributes.minW, "0pt"); this.name = attributes.name || ""; this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); this.relevant = (0, _utils.getRelevant)(attributes.relevant); this.rotate = (0, _utils.getInteger)({ data: attributes.rotate, defaultValue: 0, validate: x => x % 90 === 0 }); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.w = attributes.w ? (0, _utils.getMeasurement)(attributes.w) : ""; this.x = (0, _utils.getMeasurement)(attributes.x, "0pt"); this.y = (0, _utils.getMeasurement)(attributes.y, "0pt"); this.assist = null; this.bind = null; this.border = null; this.calculate = null; this.caption = null; this.desc = null; this.extras = null; this.font = null; this.format = null; this.items = new _xfa_object.XFAObjectArray(2); this.keep = null; this.margin = null; this.para = null; this.traversal = null; this.ui = null; this.validate = null; this.value = null; this.bindItems = new _xfa_object.XFAObjectArray(); this.connect = new _xfa_object.XFAObjectArray(); this.event = new _xfa_object.XFAObjectArray(); this.setProperty = new _xfa_object.XFAObjectArray(); } [_xfa_object.$setValue](value) { _setValue(this, value); } [_xfa_object.$toHTML]() { if (!this.ui) { return null; } const style = (0, _html_utils.toStyle)(this, "font", "dimensions", "position", "rotate", "anchorType", "presence"); const borderWidths = []; const marginWidths = []; if (this.border) { Object.assign(style, this.border[_xfa_object.$toStyle](borderWidths, marginWidths)); } if (this.margin) { style.paddingTop = (0, _html_utils.measureToString)(this.margin.topInset - borderWidths[0] - marginWidths[0]); style.paddingRight = (0, _html_utils.measureToString)(this.margin.rightInset - borderWidths[1] - marginWidths[1]); style.paddingBottom = (0, _html_utils.measureToString)(this.margin.bottomInset - borderWidths[2] - marginWidths[2]); style.paddingLeft = (0, _html_utils.measureToString)(this.margin.leftInset - borderWidths[3] - marginWidths[3]); } else { style.paddingTop = (0, _html_utils.measureToString)(-borderWidths[0] - marginWidths[0]); style.paddingRight = (0, _html_utils.measureToString)(-borderWidths[1] - marginWidths[1]); style.paddingBottom = (0, _html_utils.measureToString)(-borderWidths[2] - marginWidths[2]); style.paddingLeft = (0, _html_utils.measureToString)(-borderWidths[3] - marginWidths[3]); } const clazz = ["xfaField"]; if (this.font) { clazz.push("xfaFont"); } const attributes = { style, id: this[_xfa_object.$uid], class: clazz.join(" ") }; if (this.name) { attributes.xfaName = this.name; } const children = []; const html = { name: "div", attributes, children }; const ui = this.ui ? this.ui[_xfa_object.$toHTML]() : null; if (!ui) { return html; } if (!ui.attributes.style) { ui.attributes.style = Object.create(null); } children.push(ui); if (this.value && ui.name !== "button") { ui.children[0].attributes.value = this.value[_xfa_object.$toHTML](); } const caption = this.caption ? this.caption[_xfa_object.$toHTML]() : null; if (!caption) { return html; } if (ui.name === "button") { ui.attributes.style.background = style.color; delete style.color; if (caption.name === "div") { caption.name = "span"; } ui.children = [caption]; return html; } ui.children.splice(0, 0, caption); switch (this.caption.placement) { case "left": ui.attributes.style.flexDirection = "row"; break; case "right": ui.attributes.style.flexDirection = "row-reverse"; break; case "top": ui.attributes.style.flexDirection = "column"; break; case "bottom": ui.attributes.style.flexDirection = "column-reverse"; break; case "inline": delete ui.attributes.class; caption.attributes.style.float = "left"; break; } return html; } } exports.Field = Field; class Fill extends _xfa_object.XFAObject { constructor(attributes) { super(TEMPLATE_NS_ID, "fill", true); this.id = attributes.id || ""; this.presence = (0, _utils.getStringOption)(attributes.presence, ["visible", "hidden", "inactive", "invisible"]); this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.color = null; this.extras = null; this.linear = null; this.pattern = null; this.radial = null; this.solid = null; this.stipple = null; } [_xfa_object.$toStyle]() { for (const name of Object.getOwnPropertyNames(this)) { if (name === "extras" || name === "color") { continue; } const obj = this[name]; if (!(obj instanceof _xfa_object.XFAObject)) { continue; } return { color: obj[_xfa_object.$toStyle](this.color) }; } return { color: this.color ? this.color[_xfa_object.$toStyle]() : "#000000" }; } } class Filter extends _xfa_object.XFAObject { constructor(attributes) {