UNPKG

pdfjs-lib

Version:

Generic build of Mozilla's PDF.js library.

1,443 lines (1,442 loc) 172 kB
/** * @licstart The following is the entire license notice for the * JavaScript code in this page * * Copyright 2022 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 _layout = require("./layout.js"); var _html_utils = require("./html_utils.js"); var _utils = require("./utils.js"); var _util = require("../../shared/util.js"); var _fonts = require("./fonts.js"); var _core_utils = require("../core_utils.js"); var _som = require("./som.js"); const TEMPLATE_NS_ID = _namespaces.NamespaceIds.template.id; const SVG_NS = "http://www.w3.org/2000/svg"; const MAX_ATTEMPTS_FOR_LRTB_LAYOUT = 2; const MAX_EMPTY_PAGES = 3; const DEFAULT_TAB_INDEX = 5000; const HEADING_PATTERN = /^H(\d+)$/; const MIMES = new Set(["image/gif", "image/jpeg", "image/jpg", "image/pjpeg", "image/png", "image/apng", "image/x-png", "image/bmp", "image/x-ms-bmp", "image/tiff", "image/tif", "application/octet-stream"]); const IMAGES_HEADERS = [[[0x42, 0x4d], "image/bmp"], [[0xff, 0xd8, 0xff], "image/jpeg"], [[0x49, 0x49, 0x2a, 0x00], "image/tiff"], [[0x4d, 0x4d, 0x00, 0x2a], "image/tiff"], [[0x47, 0x49, 0x46, 0x38, 0x39, 0x61], "image/gif"], [[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], "image/png"]]; function getBorderDims(node) { if (!node || !node.border) { return { w: 0, h: 0 }; } const borderExtra = node.border[_xfa_object.$getExtra](); if (!borderExtra) { return { w: 0, h: 0 }; } return { w: borderExtra.widths[0] + borderExtra.widths[2] + borderExtra.insets[0] + borderExtra.insets[2], h: borderExtra.widths[1] + borderExtra.widths[3] + borderExtra.insets[1] + borderExtra.insets[3] }; } function hasMargin(node) { return node.margin && (node.margin.topInset || node.margin.rightInset || node.margin.bottomInset || node.margin.leftInset); } 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); } function* getContainedChildren(node) { for (const child of node[_xfa_object.$getChildren]()) { if (child instanceof SubformSet) { yield* child[_xfa_object.$getContainedChildren](); continue; } yield child; } } function isRequired(node) { return node.validate && node.validate.nullTest === "error"; } function setTabIndex(node) { while (node) { if (!node.traversal) { node[_xfa_object.$tabIndex] = node[_xfa_object.$getParent]()[_xfa_object.$tabIndex]; return; } if (node[_xfa_object.$tabIndex]) { return; } let next = null; for (const child of node.traversal[_xfa_object.$getChildren]()) { if (child.operation === "next") { next = child; break; } } if (!next || !next.ref) { node[_xfa_object.$tabIndex] = node[_xfa_object.$getParent]()[_xfa_object.$tabIndex]; return; } const root = node[_xfa_object.$getTemplateRoot](); node[_xfa_object.$tabIndex] = ++root[_xfa_object.$tabIndex]; const ref = root[_xfa_object.$searchNode](next.ref, node); if (!ref) { return; } node = ref[0]; } } function applyAssist(obj, attributes) { const assist = obj.assist; if (assist) { const assistTitle = assist[_xfa_object.$toHTML](); if (assistTitle) { attributes.title = assistTitle; } const role = assist.role; const match = role.match(HEADING_PATTERN); if (match) { const ariaRole = "heading"; const ariaLevel = match[1]; attributes.role = ariaRole; attributes["aria-level"] = ariaLevel; } } if (obj.layout === "table") { attributes.role = "table"; } else if (obj.layout === "row") { attributes.role = "row"; } else { const parent = obj[_xfa_object.$getParent](); if (parent.layout === "row") { if (parent.assist && parent.assist.role === "TH") { attributes.role = "columnheader"; } else { attributes.role = "cell"; } } } } function ariaLabel(obj) { if (!obj.assist) { return null; } const assist = obj.assist; if (assist.speak && assist.speak[_xfa_object.$content] !== "") { return assist.speak[_xfa_object.$content]; } if (assist.toolTip) { return assist.toolTip[_xfa_object.$content]; } return null; } function valueToHtml(value) { return _utils.HTMLResult.success({ name: "div", attributes: { class: ["xfaRich"], style: Object.create(null) }, children: [{ name: "span", attributes: { style: Object.create(null) }, value }] }); } function setFirstUnsplittable(node) { const root = node[_xfa_object.$getTemplateRoot](); if (root[_xfa_object.$extra].firstUnsplittable === null) { root[_xfa_object.$extra].firstUnsplittable = node; root[_xfa_object.$extra].noLayoutFailure = true; } } function unsetFirstUnsplittable(node) { const root = node[_xfa_object.$getTemplateRoot](); if (root[_xfa_object.$extra].firstUnsplittable === node) { root[_xfa_object.$extra].noLayoutFailure = false; } } function handleBreak(node) { if (node[_xfa_object.$extra]) { return false; } node[_xfa_object.$extra] = Object.create(null); if (node.targetType === "auto") { return false; } const root = node[_xfa_object.$getTemplateRoot](); let target = null; if (node.target) { target = root[_xfa_object.$searchNode](node.target, node[_xfa_object.$getParent]()); if (!target) { return false; } target = target[0]; } const { currentPageArea, currentContentArea } = root[_xfa_object.$extra]; if (node.targetType === "pageArea") { if (!(target instanceof PageArea)) { target = null; } if (node.startNew) { node[_xfa_object.$extra].target = target || currentPageArea; return true; } else if (target && target !== currentPageArea) { node[_xfa_object.$extra].target = target; return true; } return false; } if (!(target instanceof ContentArea)) { target = null; } const pageArea = target && target[_xfa_object.$getParent](); let index; let nextPageArea = pageArea; if (node.startNew) { if (target) { const contentAreas = pageArea.contentArea.children; const indexForCurrent = contentAreas.indexOf(currentContentArea); const indexForTarget = contentAreas.indexOf(target); if (indexForCurrent !== -1 && indexForCurrent < indexForTarget) { nextPageArea = null; } index = indexForTarget - 1; } else { index = currentPageArea.contentArea.children.indexOf(currentContentArea); } } else if (target && target !== currentContentArea) { const contentAreas = pageArea.contentArea.children; index = contentAreas.indexOf(target) - 1; nextPageArea = pageArea === currentPageArea ? null : pageArea; } else { return false; } node[_xfa_object.$extra].target = nextPageArea; node[_xfa_object.$extra].index = index; return true; } function handleOverflow(node, extraNode, space) { const root = node[_xfa_object.$getTemplateRoot](); const saved = root[_xfa_object.$extra].noLayoutFailure; const savedMethod = extraNode[_xfa_object.$getSubformParent]; extraNode[_xfa_object.$getSubformParent] = () => node; root[_xfa_object.$extra].noLayoutFailure = true; const res = extraNode[_xfa_object.$toHTML](space); node[_xfa_object.$addHTML](res.html, res.bbox); root[_xfa_object.$extra].noLayoutFailure = saved; extraNode[_xfa_object.$getSubformParent] = savedMethod; } 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; } [_xfa_object.$toHTML]() { const edge = this.edge || new Edge({}); const edgeStyle = edge[_xfa_object.$toStyle](); const style = Object.create(null); if (this.fill && this.fill.presence === "visible") { Object.assign(style, this.fill[_xfa_object.$toStyle]()); } else { style.fill = "transparent"; } style.strokeWidth = (0, _html_utils.measureToString)(edge.presence === "visible" ? edge.thickness : 0); style.stroke = edgeStyle.color; let arc; const attributes = { xmlns: SVG_NS, style: { width: "100%", height: "100%", overflow: "visible" } }; if (this.sweepAngle === 360) { arc = { name: "ellipse", attributes: { xmlns: SVG_NS, cx: "50%", cy: "50%", rx: "50%", ry: "50%", style } }; } else { const startAngle = this.startAngle * Math.PI / 180; const sweepAngle = this.sweepAngle * Math.PI / 180; const largeArc = this.sweepAngle > 180 ? 1 : 0; const [x1, y1, x2, y2] = [50 * (1 + Math.cos(startAngle)), 50 * (1 - Math.sin(startAngle)), 50 * (1 + Math.cos(startAngle + sweepAngle)), 50 * (1 - Math.sin(startAngle + sweepAngle))]; arc = { name: "path", attributes: { xmlns: SVG_NS, d: `M ${x1} ${y1} A 50 50 0 ${largeArc} 0 ${x2} ${y2}`, vectorEffect: "non-scaling-stroke", style } }; Object.assign(attributes, { viewBox: "0 0 100 100", preserveAspectRatio: "none" }); } const svg = { name: "svg", children: [arc], attributes }; const parent = this[_xfa_object.$getParent]()[_xfa_object.$getParent](); if (hasMargin(parent)) { return _utils.HTMLResult.success({ name: "div", attributes: { style: { display: "inline", width: "100%", height: "100%" } }, children: [svg] }); } svg.attributes.style.position = "absolute"; return _utils.HTMLResult.success(svg); } } 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 || 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.$getContainedChildren]() { yield* getContainedChildren(this); } [_xfa_object.$isTransparent]() { return true; } [_xfa_object.$isBindable]() { return true; } [_xfa_object.$addHTML](html, bbox) { const [x, y, w, h] = bbox; this[_xfa_object.$extra].width = Math.max(this[_xfa_object.$extra].width, x + w); this[_xfa_object.$extra].height = Math.max(this[_xfa_object.$extra].height, y + h); this[_xfa_object.$extra].children.push(html); } [_xfa_object.$getAvailableSpace]() { return this[_xfa_object.$extra].availableSpace; } [_xfa_object.$toHTML](availableSpace) { const style = (0, _html_utils.toStyle)(this, "position"); const attributes = { style, id: this[_xfa_object.$uid], class: ["xfaArea"] }; if ((0, _html_utils.isPrintOnly)(this)) { attributes.class.push("xfaPrintOnly"); } if (this.name) { attributes.xfaName = this.name; } const children = []; this[_xfa_object.$extra] = { children, width: 0, height: 0, availableSpace }; const result = this[_xfa_object.$childrenToHTML]({ filter: new Set(["area", "draw", "field", "exclGroup", "subform", "subformSet"]), include: true }); if (!result.success) { if (result.isBreak()) { return result; } delete this[_xfa_object.$extra]; return _utils.HTMLResult.FAILURE; } style.width = (0, _html_utils.measureToString)(this[_xfa_object.$extra].width); style.height = (0, _html_utils.measureToString)(this[_xfa_object.$extra].height); const html = { name: "div", attributes, children }; const bbox = [this.x, this.y, this[_xfa_object.$extra].width, this[_xfa_object.$extra].height]; delete this[_xfa_object.$extra]; return _utils.HTMLResult.success(html, bbox); } } 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; } [_xfa_object.$toHTML]() { return this.toolTip && this.toolTip[_xfa_object.$content] ? this.toolTip[_xfa_object.$content] : 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-\d{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](availableSpace) { return valueToHtml(this[_xfa_object.$content] === 1 ? "1" : "0"); } } 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.$getExtra]() { if (!this[_xfa_object.$extra]) { const edges = this.edge.children.slice(); if (edges.length < 4) { const defaultEdge = edges.at(-1) || new Edge({}); for (let i = edges.length; i < 4; i++) { edges.push(defaultEdge); } } const widths = edges.map(edge => edge.thickness); const insets = [0, 0, 0, 0]; if (this.margin) { insets[0] = this.margin.topInset; insets[1] = this.margin.rightInset; insets[2] = this.margin.bottomInset; insets[3] = this.margin.leftInset; } this[_xfa_object.$extra] = { widths, insets, edges }; } return this[_xfa_object.$extra]; } [_xfa_object.$toStyle]() { const { edges } = this[_xfa_object.$getExtra](); const edgeStyles = edges.map(node => { const style = node[_xfa_object.$toStyle](); style.color = style.color || "#000000"; return style; }); const style = Object.create(null); if (this.margin) { Object.assign(style, this.margin[_xfa_object.$toStyle]()); } if (this.fill && this.fill.presence === "visible") { Object.assign(style, this.fill[_xfa_object.$toStyle]()); } if (this.corner.children.some(node => node.radius !== 0)) { const cornerStyles = this.corner.children.map(node => node[_xfa_object.$toStyle]()); if (cornerStyles.length === 2 || cornerStyles.length === 3) { const last = cornerStyles.at(-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; default: style.borderStyle = edgeStyles.map(s => s.style).join(" "); break; } style.borderWidth = edgeStyles.map(s => s.width).join(" "); style.borderColor = edgeStyles.map(s => s.color).join(" "); 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"]); 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"]); this.trailer = attributes.trailer || ""; this.use = attributes.use || ""; this.usehref = attributes.usehref || ""; this.script = null; } [_xfa_object.$toHTML](availableSpace) { this[_xfa_object.$extra] = {}; return _utils.HTMLResult.FAILURE; } } 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](availableSpace) { const parent = this[_xfa_object.$getParent](); const grandpa = parent[_xfa_object.$getParent](); const htmlButton = { name: "button", attributes: { id: this[_xfa_object.$uid], class: ["xfaButton"], style: {} }, children: [] }; for (const event of grandpa.event.children) { if (event.activity !== "click" || !event.script) { continue; } const jsURL = (0, _core_utils.recoverJsURL)(event.script[_xfa_object.$content]); if (!jsURL) { continue; } const href = (0, _html_utils.fixURL)(jsURL.url); if (!href) { continue; } htmlButton.children.push({ name: "a", attributes: { id: "link" + this[_xfa_object.$uid], href, newWindow: jsURL.newWindow, class: ["xfaLink"], style: {} }, children: [] }); } return _utils.HTMLResult.success(htmlButton); } } 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 = Math.ceil((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.$getExtra](availableSpace) { if (!this[_xfa_object.$extra]) { let { width, height } = availableSpace; switch (this.placement) { case "left": case "right": case "inline": width = this.reserve <= 0 ? width : this.reserve; break; case "top": case "bottom": height = this.reserve <= 0 ? height : this.reserve; break; } this[_xfa_object.$extra] = (0, _html_utils.layoutNode)(this, { width, height }); } return this[_xfa_object.$extra]; } [_xfa_object.$toHTML](availableSpace) { if (!this.value) { return _utils.HTMLResult.EMPTY; } this[_xfa_object.$pushPara](); const value = this.value[_xfa_object.$toHTML](availableSpace).html; if (!value) { this[_xfa_object.$popPara](); return _utils.HTMLResult.EMPTY; } const savedReserve = this.reserve; if (this.reserve <= 0) { const { w, h } = this[_xfa_object.$getExtra](availableSpace); switch (this.placement) { case "left": case "right": case "inline": this.reserve = w; break; case "top": case "bottom": this.reserve = h; break; } } const children = []; if (typeof value === "string") { children.push({ name: "#text", value }); } else { children.push(value); } const style = (0, _html_utils.toStyle)(this, "font", "margin", "visibility"); switch (this.placement) { case "left": case "right": if (this.reserve > 0) { style.width = (0, _html_utils.measureToString)(this.reserve); } break; case "top": case "bottom": if (this.reserve > 0) { style.height = (0, _html_utils.measureToString)(this.reserve); } break; } (0, _html_utils.setPara)(this, null, value); this[_xfa_object.$popPara](); this.reserve = savedReserve; return _utils.HTMLResult.success({ name: "div", attributes: { style, class: ["xfaCaption"] }, 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](availableSpace) { const style = (0, _html_utils.toStyle)("margin"); const size = (0, _html_utils.measureToString)(this.size); style.width = style.height = size; let type; let className; let groupId; const field = this[_xfa_object.$getParent]()[_xfa_object.$getParent](); const items = field.items.children.length && field.items.children[0][_xfa_object.$toHTML]().html || []; const exportedValue = { on: (items[0] !== undefined ? items[0] : "on").toString(), off: (items[1] !== undefined ? items[1] : "off").toString() }; const value = field.value && field.value[_xfa_object.$text]() || "off"; const checked = value === exportedValue.on || undefined; const container = field[_xfa_object.$getSubformParent](); const fieldId = field[_xfa_object.$uid]; let dataId; if (container instanceof ExclGroup) { groupId = container[_xfa_object.$uid]; type = "radio"; className = "xfaRadio"; dataId = container[_xfa_object.$data] && container[_xfa_object.$data][_xfa_object.$uid] || container[_xfa_object.$uid]; } else { type = "checkbox"; className = "xfaCheckbox"; dataId = field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid]; } const input = { name: "input", attributes: { class: [className], style, fieldId, dataId, type, checked, xfaOn: exportedValue.on, xfaOff: exportedValue.off, "aria-label": ariaLabel(field), "aria-required": false } }; if (groupId) { input.attributes.name = groupId; } if (isRequired(field)) { input.attributes["aria-required"] = true; input.attributes.required = true; } return _utils.HTMLResult.success({ name: "label", attributes: { class: ["xfaLabel"] }, children: [input] }); } } 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](availableSpace) { const style = (0, _html_utils.toStyle)(this, "border", "margin"); const ui = this[_xfa_object.$getParent](); const field = ui[_xfa_object.$getParent](); const fontSize = field.font && field.font.size || 10; const optionStyle = { fontSize: `calc(${fontSize}px * var(--scale-factor))` }; const children = []; if (field.items.children.length > 0) { const items = field.items; let displayedIndex = 0; let saveIndex = 0; if (items.children.length === 2) { displayedIndex = items.children[0].save; saveIndex = 1 - displayedIndex; } const displayed = items.children[displayedIndex][_xfa_object.$toHTML]().html; const values = items.children[saveIndex][_xfa_object.$toHTML]().html; let selected = false; const value = field.value && field.value[_xfa_object.$text]() || ""; for (let i = 0, ii = displayed.length; i < ii; i++) { const option = { name: "option", attributes: { value: values[i] || displayed[i], style: optionStyle }, value: displayed[i] }; if (values[i] === value) { option.attributes.selected = selected = true; } children.push(option); } if (!selected) { children.splice(0, 0, { name: "option", attributes: { hidden: true, selected: true }, value: " " }); } } const selectAttributes = { class: ["xfaSelect"], fieldId: field[_xfa_object.$uid], dataId: field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid], style, "aria-label": ariaLabel(field), "aria-required": false }; if (isRequired(field)) { selectAttributes["aria-required"] = true; selectAttributes.required = true; } if (this.open === "multiSelect") { selectAttributes.multiple = true; } return _utils.HTMLResult.success({ name: "label", attributes: { class: ["xfaLabel"] }, children: [{ name: "select", children, attributes: selectAttributes }] }); } } 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 = attributes.value ? (0, _utils.getColor)(attributes.value) : ""; this.extras = null; } [_xfa_object.$hasSettableValue]() { return false; } [_xfa_object.$toStyle]() { return this.value ? _util.Util.makeHexColor(this.value.r, this.value.g, this.value.b) : null; } } 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](availableSpace) { const left = (0, _html_utils.measureToString)(this.x); const top = (0, _html_utils.measureToString)(this.y); const style = { left, top, width: (0, _html_utils.measureToString)(this.w), height: (0, _html_utils.measureToString)(this.h) }; const classNames = ["xfaContentarea"]; if ((0, _html_utils.isPrintOnly)(this)) { classNames.push("xfaPrintOnly"); } return _utils.HTMLResult.success({ name: "div", children: [], attributes: { style, class: classNames, 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.join === "square" ? 0 : 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]() { const date = this[_xfa_object.$content].trim(); this[_xfa_object.$content] = date ? new Date(date) : null; } [_xfa_object.$toHTML](availableSpace) { return valueToHtml(this[_xfa_object.$content] ? 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]() { const date = this[_xfa_object.$content].trim(); this[_xfa_object.$content] = date ? new Date(date) : null; } [_xfa_object.$toHTML](availableSpace) { return valueToHtml(this[_xfa_object.$content] ? 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](availableSpace) { const style = (0, _html_utils.toStyle)(this, "border", "font", "margin"); const field = this[_xfa_object.$getParent]()[_xfa_object.$getParent](); const html = { name: "input", attributes: { type: "text", fieldId: field[_xfa_object.$uid], dataId: field[_xfa_object.$data] && field[_xfa_object.$data][_xfa_object.$uid] || field[_xfa_object.$uid], class: ["xfaTextfield"], style, "aria-label": ariaLabel(field), "aria-required": false } }; if (isRequired(field)) { html.attributes["aria-required"] = true; html.attributes.required = true; } return _utils.HTMLResult.success({ 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](availableSpace) { return valueToHtml(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: n => n >= 1 || n === -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](availableSpace) { setTabIndex(this); if (this.presence === "hidden" || this.presence === "inactive") { return _utils.HTMLResult.EMPTY; } (0, _html_utils.fixDimensions)(this); this[_xfa_object.$pushPara](); const savedW = this.w; const savedH = this.h; const { w, h, isBroken } = (0, _html_utils.layoutNode)(this, availableSpace); if (w && this.w === "") { if (isBroken && this[_xfa_object.$getSubformParent]()[_xfa_object.$isThereMoreWidth]()) { this[_xfa_object.$popPara](); return _utils.HTMLResult.FAILURE; } this.w = w; } if (h && this.h === "") { this.h = h; } setFirstUnsplittable(this); if (!(0, _layout.checkDimensions)(this, availableSpace)) { this.w = savedW; this.h = savedH; this[_xfa_object.$popPara](); return _utils.HTMLResult.FAILURE; } unsetFirstUnsplittable(this); const style = (0, _html_utils.toStyle)(this, "font", "hAlign", "dimensions", "position", "presence", "rotate", "anchorType", "border", "margin"); (0, _html_utils.setMinMaxDimensions)(this, style); if (style.margin) { style.padding = style.margin; delete style.margin; } const classNames = ["xfaDraw"]; if (this.font) { classNames.push("xfaFont"); } if ((0, _html_utils.isPrintOnly)(this)) { classNames.push("xfaPrintOnly"); } const attributes = { style, id: this[_xfa_object.$uid], class: classNames }; if (this.name) { attributes.xfaName = this.name; } const html = { name: "div", attributes, children: [] }; applyAssist(this, attributes); const bbox = (0, _html_utils.computeBbox)(this, html, availableSpace); const value = this.value ? this.value[_xfa_object.$toHTML](availableSpace).html : null; if (value === null) { this.w = savedW; this.h = savedH; this[_xfa_object.$popPara](); return _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox); } html.children.push(value); (0, _html_utils.setPara)(this, style, value); this.w = savedW; this.h = savedH; this[_xfa_object.$popPara](); return _utils.HTMLResult.success((0, _html_utils.createWrapper)(this, html), bbox); } } class Edge extends _xfa_object.XFAObject { constructor(