From d44f75dbba5952e9cc287f55cc8d13addac6a1a6 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Tue, 12 Oct 2021 23:49:41 +0000 Subject: [PATCH] Bug 1735409 - Update pdf.js to version 2.12.16 r=pdfjs-reviewers,marco Differential Revision: https://phabricator.services.mozilla.com/D128291 --- toolkit/components/pdfjs/README.mozilla | 4 +- toolkit/components/pdfjs/content/build/pdf.js | 512 +++++++++------ .../pdfjs/content/build/pdf.scripting.js | 16 +- .../pdfjs/content/build/pdf.worker.js | 604 ++++++++++++------ .../components/pdfjs/content/web/viewer.css | 18 +- .../components/pdfjs/content/web/viewer.js | 73 ++- toolkit/components/pdfjs/moz.yaml | 2 +- 7 files changed, 821 insertions(+), 408 deletions(-) diff --git a/toolkit/components/pdfjs/README.mozilla b/toolkit/components/pdfjs/README.mozilla index 39faa5ef21be..57f5484e7f0a 100644 --- a/toolkit/components/pdfjs/README.mozilla +++ b/toolkit/components/pdfjs/README.mozilla @@ -1,5 +1,5 @@ This is the PDF.js project output, https://github.com/mozilla/pdf.js -Current extension version is: 2.11.298 +Current extension version is: 2.12.16 -Taken from upstream commit: d370a281c +Taken from upstream commit: 394596560 diff --git a/toolkit/components/pdfjs/content/build/pdf.js b/toolkit/components/pdfjs/content/build/pdf.js index 9606eeb98e67..ec2df88f9b11 100644 --- a/toolkit/components/pdfjs/content/build/pdf.js +++ b/toolkit/components/pdfjs/content/build/pdf.js @@ -51,14 +51,13 @@ exports.isDataScheme = isDataScheme; exports.isPdfFile = isPdfFile; exports.isValidFetchUrl = isValidFetchUrl; exports.loadScript = loadScript; -exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PDFDateString = exports.PageViewport = exports.LinkTarget = exports.DOMSVGFactory = exports.DOMStandardFontDataFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = void 0; +exports.StatTimer = exports.RenderingCancelledException = exports.PixelsPerInch = exports.PDFDateString = exports.PageViewport = exports.LinkTarget = exports.DOMSVGFactory = exports.DOMStandardFontDataFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = void 0; var _util = __w_pdfjs_require__(2); var _base_factory = __w_pdfjs_require__(5); const DEFAULT_LINK_REL = "noopener noreferrer nofollow"; -exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL; const SVG_NS = "http://www.w3.org/2000/svg"; const PixelsPerInch = { CSS: 96.0, @@ -972,12 +971,28 @@ function _isValidProtocol(url) { } } -function createValidAbsoluteUrl(url, baseUrl) { +function createValidAbsoluteUrl(url, baseUrl = null, options = null) { if (!url) { return null; } try { + if (options && typeof url === "string") { + if (options.addDefaultProtocol && url.startsWith("www.")) { + const dots = url.match(/\./g); + + if (dots && dots.length >= 2) { + url = `http://${url}`; + } + } + + if (options.tryConvertEncoding) { + try { + url = stringToUTF8String(url); + } catch (ex) {} + } + } + const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url); if (_isValidProtocol(absoluteUrl)) { @@ -1912,7 +1927,7 @@ async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", { docId, - apiVersion: '2.11.298', + apiVersion: '2.12.16', source: { data: source.data, url: source.url, @@ -2718,84 +2733,14 @@ exports.PDFPageProxy = PDFPageProxy; class LoopbackPort { constructor() { this._listeners = []; - this._deferred = Promise.resolve(undefined); + this._deferred = Promise.resolve(); } postMessage(obj, transfers) { - function cloneValue(value) { - if (typeof value === "function" || typeof value === "symbol" || value instanceof URL) { - throw new Error(`LoopbackPort.postMessage - cannot clone: ${value?.toString()}`); - } - - if (typeof value !== "object" || value === null) { - return value; - } - - if (cloned.has(value)) { - return cloned.get(value); - } - - let buffer, result; - - if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) { - if (transfers?.includes(buffer)) { - result = new value.constructor(buffer, value.byteOffset, value.byteLength); - } else { - result = new value.constructor(value); - } - - cloned.set(value, result); - return result; - } - - if (value instanceof Map) { - result = new Map(); - cloned.set(value, result); - - for (const [key, val] of value) { - result.set(key, cloneValue(val)); - } - - return result; - } - - if (value instanceof Set) { - result = new Set(); - cloned.set(value, result); - - for (const val of value) { - result.add(cloneValue(val)); - } - - return result; - } - - result = Array.isArray(value) ? [] : Object.create(null); - cloned.set(value, result); - - for (const i in value) { - let desc, - p = value; - - while (!(desc = Object.getOwnPropertyDescriptor(p, i))) { - p = Object.getPrototypeOf(p); - } - - if (typeof desc.value === "undefined") { - continue; - } - - if (typeof desc.value === "function" && !value.hasOwnProperty?.(i)) { - continue; - } - - result[i] = cloneValue(desc.value); - } - - return result; + function cloneValue(object) { + return globalThis.structuredClone(object, transfers); } - const cloned = new WeakMap(); const event = { data: cloneValue(obj) }; @@ -3996,9 +3941,9 @@ class InternalRenderTask { } -const version = '2.11.298'; +const version = '2.12.16'; exports.version = version; -const build = 'd370a281c'; +const build = '394596560'; exports.build = build; /***/ }), @@ -7594,10 +7539,10 @@ class MessageHandler { } sendWithStream(actionName, data, queueingStrategy, transfers) { - const streamId = this.streamId++; - const sourceName = this.sourceName; - const targetName = this.targetName; - const comObj = this.comObj; + const streamId = this.streamId++, + sourceName = this.sourceName, + targetName = this.targetName, + comObj = this.comObj; return new ReadableStream({ start: controller => { const startCapability = (0, _util.createPromiseCapability)(); @@ -7650,12 +7595,12 @@ class MessageHandler { } _createStreamSink(data) { - const self = this; - const action = this.actionHandler[data.action]; - const streamId = data.streamId; - const sourceName = this.sourceName; - const targetName = data.sourceName; - const comObj = this.comObj; + const streamId = data.streamId, + sourceName = this.sourceName, + targetName = data.sourceName, + comObj = this.comObj; + const self = this, + action = this.actionHandler[data.action]; const streamSink = { enqueue(chunk, size = 1, transfers) { if (this.isCancelled) { @@ -7743,32 +7688,34 @@ class MessageHandler { } _processStreamMessage(data) { - const streamId = data.streamId; - const sourceName = this.sourceName; - const targetName = data.sourceName; - const comObj = this.comObj; + const streamId = data.streamId, + sourceName = this.sourceName, + targetName = data.sourceName, + comObj = this.comObj; + const streamController = this.streamControllers[streamId], + streamSink = this.streamSinks[streamId]; switch (data.stream) { case StreamKind.START_COMPLETE: if (data.success) { - this.streamControllers[streamId].startCall.resolve(); + streamController.startCall.resolve(); } else { - this.streamControllers[streamId].startCall.reject(wrapReason(data.reason)); + streamController.startCall.reject(wrapReason(data.reason)); } break; case StreamKind.PULL_COMPLETE: if (data.success) { - this.streamControllers[streamId].pullCall.resolve(); + streamController.pullCall.resolve(); } else { - this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason)); + streamController.pullCall.reject(wrapReason(data.reason)); } break; case StreamKind.PULL: - if (!this.streamSinks[streamId]) { + if (!streamSink) { comObj.postMessage({ sourceName, targetName, @@ -7779,16 +7726,13 @@ class MessageHandler { break; } - if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) { - this.streamSinks[streamId].sinkCapability.resolve(); + if (streamSink.desiredSize <= 0 && data.desiredSize > 0) { + streamSink.sinkCapability.resolve(); } - this.streamSinks[streamId].desiredSize = data.desiredSize; - const { - onPull - } = this.streamSinks[streamId]; + streamSink.desiredSize = data.desiredSize; new Promise(function (resolve) { - resolve(onPull && onPull()); + resolve(streamSink.onPull && streamSink.onPull()); }).then(function () { comObj.postMessage({ sourceName, @@ -7809,58 +7753,55 @@ class MessageHandler { break; case StreamKind.ENQUEUE: - (0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller"); + (0, _util.assert)(streamController, "enqueue should have stream controller"); - if (this.streamControllers[streamId].isClosed) { + if (streamController.isClosed) { break; } - this.streamControllers[streamId].controller.enqueue(data.chunk); + streamController.controller.enqueue(data.chunk); break; case StreamKind.CLOSE: - (0, _util.assert)(this.streamControllers[streamId], "close should have stream controller"); + (0, _util.assert)(streamController, "close should have stream controller"); - if (this.streamControllers[streamId].isClosed) { + if (streamController.isClosed) { break; } - this.streamControllers[streamId].isClosed = true; - this.streamControllers[streamId].controller.close(); + streamController.isClosed = true; + streamController.controller.close(); - this._deleteStreamController(streamId); + this._deleteStreamController(streamController, streamId); break; case StreamKind.ERROR: - (0, _util.assert)(this.streamControllers[streamId], "error should have stream controller"); - this.streamControllers[streamId].controller.error(wrapReason(data.reason)); + (0, _util.assert)(streamController, "error should have stream controller"); + streamController.controller.error(wrapReason(data.reason)); - this._deleteStreamController(streamId); + this._deleteStreamController(streamController, streamId); break; case StreamKind.CANCEL_COMPLETE: if (data.success) { - this.streamControllers[streamId].cancelCall.resolve(); + streamController.cancelCall.resolve(); } else { - this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason)); + streamController.cancelCall.reject(wrapReason(data.reason)); } - this._deleteStreamController(streamId); + this._deleteStreamController(streamController, streamId); break; case StreamKind.CANCEL: - if (!this.streamSinks[streamId]) { + if (!streamSink) { break; } - const { - onCancel - } = this.streamSinks[streamId]; new Promise(function (resolve) { - resolve(onCancel && onCancel(wrapReason(data.reason))); + resolve(streamSink.onCancel && streamSink.onCancel(wrapReason(data.reason))); }).then(function () { comObj.postMessage({ sourceName, @@ -7878,8 +7819,8 @@ class MessageHandler { reason: wrapReason(reason) }); }); - this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason)); - this.streamSinks[streamId].isCancelled = true; + streamSink.sinkCapability.reject(wrapReason(data.reason)); + streamSink.isCancelled = true; delete this.streamSinks[streamId]; break; @@ -7888,10 +7829,8 @@ class MessageHandler { } } - async _deleteStreamController(streamId) { - await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) { - return capability && capability.promise; - })); + async _deleteStreamController(streamController, streamId) { + await Promise.allSettled([streamController.startCall && streamController.startCall.promise, streamController.pullCall && streamController.pullCall.promise, streamController.cancelCall && streamController.cancelCall.promise]); delete this.streamControllers[streamId]; } @@ -8604,10 +8543,10 @@ Object.defineProperty(exports, "__esModule", ({ })); exports.AnnotationLayer = void 0; -var _display_utils = __w_pdfjs_require__(1); - var _util = __w_pdfjs_require__(2); +var _display_utils = __w_pdfjs_require__(1); + var _annotation_storage = __w_pdfjs_require__(9); var _scripting_utils = __w_pdfjs_require__(19); @@ -8786,7 +8725,9 @@ class AnnotationElement { break; } - if (data.color) { + const borderColor = data.borderColor || data.color || null; + + if (borderColor) { container.style.borderColor = _util.Util.makeHexColor(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0); } else { container.style.borderWidth = 0; @@ -8836,9 +8777,9 @@ class AnnotationElement { container, trigger, color: data.color, - title: data.title, + titleObj: data.titleObj, modificationDate: data.modificationDate, - contents: data.contents, + contentsObj: data.contentsObj, hideWrapper: true }); const popup = popupElement.render(); @@ -8933,7 +8874,7 @@ class AnnotationElement { class LinkAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action || parameters.data.isTooltipOnly || parameters.data.actions && (parameters.data.actions.Action || parameters.data.actions["Mouse Up"] || parameters.data.actions["Mouse Down"])); + const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action || parameters.data.isTooltipOnly || parameters.data.resetForm || parameters.data.actions && (parameters.data.actions.Action || parameters.data.actions["Mouse Up"] || parameters.data.actions["Mouse Down"])); super(parameters, { isRenderable, createQuadrilaterals: true @@ -8948,20 +8889,25 @@ class LinkAnnotationElement extends AnnotationElement { const link = document.createElement("a"); if (data.url) { - (0, _display_utils.addLinkAttributes)(link, { - url: data.url, - target: data.newWindow ? _display_utils.LinkTarget.BLANK : linkService.externalLinkTarget, - rel: linkService.externalLinkRel, - enabled: linkService.externalLinkEnabled - }); + linkService.addLinkAttributes?.(link, data.url, data.newWindow); } else if (data.action) { this._bindNamedAction(link, data.action); } else if (data.dest) { this._bindLink(link, data.dest); - } else if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) { - this._bindJSAction(link, data); } else { - this._bindLink(link, ""); + let hasClickAction = false; + + if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) { + hasClickAction = true; + + this._bindJSAction(link, data); + } + + if (data.resetForm) { + this._bindResetFormAction(link, data.resetForm); + } else if (!hasClickAction) { + this._bindLink(link, ""); + } } if (this.quadrilaterals) { @@ -9034,11 +8980,136 @@ class LinkAnnotationElement extends AnnotationElement { link.className = "internalLink"; } + _bindResetFormAction(link, resetForm) { + const otherClickAction = link.onclick; + + if (!otherClickAction) { + link.href = this.linkService.getAnchorUrl(""); + } + + link.className = "internalLink"; + + if (!this._fieldObjects) { + (0, _util.warn)(`_bindResetFormAction - "resetForm" action not supported, ` + "ensure that the `fieldObjects` parameter is provided."); + + if (!otherClickAction) { + link.onclick = () => false; + } + + return; + } + + link.onclick = () => { + if (otherClickAction) { + otherClickAction(); + } + + const { + fields: resetFormFields, + refs: resetFormRefs, + include + } = resetForm; + const allFields = []; + + if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) { + const fieldIds = new Set(resetFormRefs); + + for (const fieldName of resetFormFields) { + const fields = this._fieldObjects[fieldName] || []; + + for (const { + id + } of fields) { + fieldIds.add(id); + } + } + + for (const fields of Object.values(this._fieldObjects)) { + for (const field of fields) { + if (fieldIds.has(field.id) === include) { + allFields.push(field); + } + } + } + } else { + for (const fields of Object.values(this._fieldObjects)) { + allFields.push(...fields); + } + } + + const storage = this.annotationStorage; + const allIds = []; + + for (const field of allFields) { + const { + id + } = field; + allIds.push(id); + + switch (field.type) { + case "text": + { + const value = field.defaultValue || ""; + storage.setValue(id, { + value, + valueAsString: value + }); + break; + } + + case "checkbox": + case "radiobutton": + { + const value = field.defaultValue === field.exportValues; + storage.setValue(id, { + value + }); + break; + } + + case "combobox": + case "listbox": + { + const value = field.defaultValue || ""; + storage.setValue(id, { + value + }); + break; + } + + default: + continue; + } + + const domElement = document.getElementById(id); + + if (!domElement || !GetElementsByNameSet.has(domElement)) { + continue; + } + + domElement.dispatchEvent(new Event("resetform")); + } + + if (this.enableScripting) { + this.linkService.eventBus?.dispatch("dispatcheventinsandbox", { + source: this, + detail: { + id: "app", + ids: allIds, + name: "ResetForm" + } + }); + } + + return false; + }; + } + } class TextAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable }); @@ -9119,6 +9190,11 @@ class WidgetAnnotationElement extends AnnotationElement { } } + _setBackgroundColor(element) { + const color = this.data.backgroundColor || null; + element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]); + } + _dispatchEventFromSandbox(actions, jsEvent) { const setColor = (jsName, styleName, event) => { const color = event.detail[jsName]; @@ -9260,6 +9336,11 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { }); this.setPropertyOnSiblings(element, "value", event.target.value, "value"); }); + element.addEventListener("resetform", event => { + const defaultValue = this.data.defaultFieldValue || ""; + element.value = elementData.userValue = defaultValue; + delete elementData.formattedValue; + }); let blurListener = event => { if (elementData.formattedValue) { @@ -9427,6 +9508,8 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { this._setTextStyle(element); + this._setBackgroundColor(element); + this.container.appendChild(element); return this.container; } @@ -9464,7 +9547,7 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement { const data = this.data; const id = data.id; let value = storage.getValue(id, { - value: data.fieldValue && (data.exportValue && data.exportValue === data.fieldValue || !data.exportValue && data.fieldValue !== "Off") + value: data.exportValue === data.fieldValue }).value; if (typeof value === "string") { @@ -9510,6 +9593,10 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement { value: checked }); }); + element.addEventListener("resetform", event => { + const defaultValue = data.defaultFieldValue || "Off"; + event.target.checked = defaultValue === data.exportValue; + }); if (this.enableScripting && this.hasJSActions) { element.addEventListener("updatefromsandbox", jsEvent => { @@ -9529,6 +9616,8 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement { this._setEventListeners(element, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked); } + this._setBackgroundColor(element); + this.container.appendChild(element); return this.container; } @@ -9586,6 +9675,10 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement { value: checked }); }); + element.addEventListener("resetform", event => { + const defaultValue = data.defaultFieldValue; + event.target.checked = defaultValue !== null && defaultValue !== undefined && defaultValue === data.buttonValue; + }); if (this.enableScripting && this.hasJSActions) { const pdfButtonValue = data.buttonValue; @@ -9614,6 +9707,8 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement { this._setEventListeners(element, [["change", "Validate"], ["change", "Action"], ["focus", "Focus"], ["blur", "Blur"], ["mousedown", "Mouse Down"], ["mouseenter", "Mouse Enter"], ["mouseleave", "Mouse Exit"], ["mouseup", "Mouse Up"]], event => event.target.checked); } + this._setBackgroundColor(element); + this.container.appendChild(element); return this.container; } @@ -9673,6 +9768,14 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { } } + selectElement.addEventListener("resetform", event => { + const defaultValue = this.data.defaultFieldValue; + + for (const option of selectElement.options) { + option.selected = option.value === defaultValue; + } + }); + for (const option of this.data.options) { const optionElement = document.createElement("option"); optionElement.textContent = option.displayValue; @@ -9714,12 +9817,13 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { selectElement.addEventListener("updatefromsandbox", jsEvent => { const actions = { value(event) { - const options = selectElement.options; const value = event.detail.value; const values = new Set(Array.isArray(value) ? value : [value]); - Array.prototype.forEach.call(options, option => { + + for (const option of selectElement.options) { option.selected = values.has(option.value); - }); + } + storage.setValue(id, { value: getValue(event, true) }); @@ -9808,10 +9912,11 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { indices(event) { const indices = new Set(event.detail.indices); - const options = event.target.options; - Array.prototype.forEach.call(options, (option, i) => { - option.selected = indices.has(i); - }); + + for (const option of event.target.options) { + option.selected = indices.has(option.index); + } + storage.setValue(id, { value: getValue(event, true) }); @@ -9854,6 +9959,8 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { }); } + this._setBackgroundColor(selectElement); + this.container.appendChild(selectElement); return this.container; } @@ -9862,7 +9969,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { class PopupAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable }); @@ -9887,9 +9994,9 @@ class PopupAnnotationElement extends AnnotationElement { container: this.container, trigger: Array.from(parentElements), color: this.data.color, - title: this.data.title, + titleObj: this.data.titleObj, modificationDate: this.data.modificationDate, - contents: this.data.contents + contentsObj: this.data.contentsObj }); const page = this.page; @@ -9911,9 +10018,9 @@ class PopupElement { this.container = parameters.container; this.trigger = parameters.trigger; this.color = parameters.color; - this.title = parameters.title; + this.titleObj = parameters.titleObj; this.modificationDate = parameters.modificationDate; - this.contents = parameters.contents; + this.contentsObj = parameters.contentsObj; this.hideWrapper = parameters.hideWrapper || false; this.pinned = false; } @@ -9936,7 +10043,8 @@ class PopupElement { } const title = document.createElement("h1"); - title.textContent = this.title; + title.dir = this.titleObj.dir; + title.textContent = this.titleObj.str; popup.appendChild(title); const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate); @@ -9952,7 +10060,7 @@ class PopupElement { popup.appendChild(modificationDate); } - const contents = this._formatContents(this.contents); + const contents = this._formatContents(this.contentsObj); popup.appendChild(contents); @@ -9971,9 +10079,13 @@ class PopupElement { return wrapper; } - _formatContents(contents) { + _formatContents({ + str, + dir + }) { const p = document.createElement("p"); - const lines = contents.split(/(?:\r\n?|\n)/); + p.dir = dir; + const lines = str.split(/(?:\r\n?|\n)/); for (let i = 0, ii = lines.length; i < ii; ++i) { const line = lines[i]; @@ -10021,7 +10133,7 @@ class PopupElement { class FreeTextAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true @@ -10042,7 +10154,7 @@ class FreeTextAnnotationElement extends AnnotationElement { class LineAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true @@ -10062,6 +10174,7 @@ class LineAnnotationElement extends AnnotationElement { line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]); line.setAttribute("stroke-width", data.borderStyle.width || 1); line.setAttribute("stroke", "transparent"); + line.setAttribute("fill", "transparent"); svg.appendChild(line); this.container.append(svg); @@ -10074,7 +10187,7 @@ class LineAnnotationElement extends AnnotationElement { class SquareAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true @@ -10095,7 +10208,7 @@ class SquareAnnotationElement extends AnnotationElement { square.setAttribute("height", height - borderWidth); square.setAttribute("stroke-width", borderWidth || 1); square.setAttribute("stroke", "transparent"); - square.setAttribute("fill", "none"); + square.setAttribute("fill", "transparent"); svg.appendChild(square); this.container.append(svg); @@ -10108,7 +10221,7 @@ class SquareAnnotationElement extends AnnotationElement { class CircleAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true @@ -10129,7 +10242,7 @@ class CircleAnnotationElement extends AnnotationElement { circle.setAttribute("ry", height / 2 - borderWidth / 2); circle.setAttribute("stroke-width", borderWidth || 1); circle.setAttribute("stroke", "transparent"); - circle.setAttribute("fill", "none"); + circle.setAttribute("fill", "transparent"); svg.appendChild(circle); this.container.append(svg); @@ -10142,7 +10255,7 @@ class CircleAnnotationElement extends AnnotationElement { class PolylineAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true @@ -10170,7 +10283,7 @@ class PolylineAnnotationElement extends AnnotationElement { polyline.setAttribute("points", points); polyline.setAttribute("stroke-width", data.borderStyle.width || 1); polyline.setAttribute("stroke", "transparent"); - polyline.setAttribute("fill", "none"); + polyline.setAttribute("fill", "transparent"); svg.appendChild(polyline); this.container.append(svg); @@ -10192,7 +10305,7 @@ class PolygonAnnotationElement extends PolylineAnnotationElement { class CaretAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true @@ -10213,7 +10326,7 @@ class CaretAnnotationElement extends AnnotationElement { class InkAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true @@ -10243,7 +10356,7 @@ class InkAnnotationElement extends AnnotationElement { polyline.setAttribute("points", points); polyline.setAttribute("stroke-width", data.borderStyle.width || 1); polyline.setAttribute("stroke", "transparent"); - polyline.setAttribute("fill", "none"); + polyline.setAttribute("fill", "transparent"); this._createPopup(polyline, data); @@ -10258,7 +10371,7 @@ class InkAnnotationElement extends AnnotationElement { class HighlightAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true, @@ -10283,7 +10396,7 @@ class HighlightAnnotationElement extends AnnotationElement { class UnderlineAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true, @@ -10308,7 +10421,7 @@ class UnderlineAnnotationElement extends AnnotationElement { class SquigglyAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true, @@ -10333,7 +10446,7 @@ class SquigglyAnnotationElement extends AnnotationElement { class StrikeOutAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true, @@ -10358,7 +10471,7 @@ class StrikeOutAnnotationElement extends AnnotationElement { class StampAnnotationElement extends AnnotationElement { constructor(parameters) { - const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + const isRenderable = !!(parameters.data.hasPopup || parameters.data.titleObj?.str || parameters.data.contentsObj?.str); super(parameters, { isRenderable, ignoreBorder: true @@ -10403,7 +10516,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement { trigger.style.width = this.container.style.width; trigger.addEventListener("dblclick", this._download.bind(this)); - if (!this.data.hasPopup && (this.data.title || this.data.contents)) { + if (!this.data.hasPopup && (this.data.titleObj?.str || this.data.contentsObj?.str)) { this._createPopup(trigger, this.data); } @@ -11388,6 +11501,8 @@ Object.defineProperty(exports, "__esModule", ({ })); exports.XfaLayer = void 0; +var _util = __w_pdfjs_require__(2); + var _xfa_text = __w_pdfjs_require__(17); class XfaLayer { @@ -11468,10 +11583,17 @@ class XfaLayer { } } - static setAttributes(html, element, storage, intent) { + static setAttributes({ + html, + element, + storage = null, + intent, + linkService + }) { const { attributes } = element; + const isHTMLAnchorElement = html instanceof HTMLAnchorElement; if (attributes.type === "radio") { attributes.name = `${attributes.name}-${intent}`; @@ -11488,6 +11610,10 @@ class XfaLayer { } else if (key === "class") { html.setAttribute(key, value.join(" ")); } else { + if (isHTMLAnchorElement && (key === "href" || key === "newWindow")) { + continue; + } + html.setAttribute(key, value); } } else { @@ -11495,6 +11621,10 @@ class XfaLayer { } } + if (isHTMLAnchorElement) { + linkService.addLinkAttributes?.(html, attributes.href, attributes.newWindow); + } + if (storage && attributes.dataId) { this.setupStorage(html, attributes.dataId, element, storage); } @@ -11502,12 +11632,18 @@ class XfaLayer { static render(parameters) { const storage = parameters.annotationStorage; + const linkService = parameters.linkService; const root = parameters.xfa; const intent = parameters.intent || "display"; const rootHtml = document.createElement(root.name); if (root.attributes) { - this.setAttributes(rootHtml, root); + this.setAttributes({ + html: rootHtml, + element: root, + intent, + linkService + }); } const stack = [[root, -1, rootHtml]]; @@ -11554,7 +11690,13 @@ class XfaLayer { html.appendChild(childHtml); if (child.attributes) { - this.setAttributes(childHtml, child, storage, intent); + this.setAttributes({ + html: childHtml, + element: child, + storage, + intent, + linkService + }); } if (child.children && child.children.length > 0) { @@ -11867,8 +12009,8 @@ var _svg = __w_pdfjs_require__(21); var _xfa_layer = __w_pdfjs_require__(22); -const pdfjsVersion = '2.11.298'; -const pdfjsBuild = 'd370a281c'; +const pdfjsVersion = '2.12.16'; +const pdfjsBuild = '394596560'; ; })(); diff --git a/toolkit/components/pdfjs/content/build/pdf.scripting.js b/toolkit/components/pdfjs/content/build/pdf.scripting.js index 8cd8e624d020..de949f07f774 100644 --- a/toolkit/components/pdfjs/content/build/pdf.scripting.js +++ b/toolkit/components/pdfjs/content/build/pdf.scripting.js @@ -927,6 +927,10 @@ class Field extends _pdf_object.PDFObject { return false; } + _reset() { + this.value = this.valueAsString = this.defaultValue; + } + _runActions(event) { const eventName = event.name; @@ -2643,6 +2647,14 @@ class EventDispatcher { this._document.obj._dispatchDocEvent(event.name); } else if (id === "page") { this._document.obj._dispatchPageEvent(event.name, baseEvent.actions, baseEvent.pageNumber); + } else if (id === "app" && baseEvent.name === "ResetForm") { + for (const fieldId of baseEvent.ids) { + const obj = this._objects[fieldId]; + + if (obj) { + obj.obj._reset(); + } + } } return; @@ -4932,8 +4944,8 @@ Object.defineProperty(exports, "initSandbox", ({ var _initialization = __w_pdfjs_require__(1); -const pdfjsVersion = '2.11.298'; -const pdfjsBuild = 'd370a281c'; +const pdfjsVersion = '2.12.16'; +const pdfjsBuild = '394596560'; })(); /******/ return __webpack_exports__; diff --git a/toolkit/components/pdfjs/content/build/pdf.worker.js b/toolkit/components/pdfjs/content/build/pdf.worker.js index 498a90001458..ab16296daa50 100644 --- a/toolkit/components/pdfjs/content/build/pdf.worker.js +++ b/toolkit/components/pdfjs/content/build/pdf.worker.js @@ -125,7 +125,7 @@ class WorkerMessageHandler { const WorkerTasks = []; const verbosity = (0, _util.getVerbosityLevel)(); const apiVersion = docParams.apiVersion; - const workerVersion = '2.11.298'; + const workerVersion = '2.12.16'; if (apiVersion !== workerVersion) { throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); @@ -1161,12 +1161,28 @@ function _isValidProtocol(url) { } } -function createValidAbsoluteUrl(url, baseUrl) { +function createValidAbsoluteUrl(url, baseUrl = null, options = null) { if (!url) { return null; } try { + if (options && typeof url === "string") { + if (options.addDefaultProtocol && url.startsWith("www.")) { + const dots = url.match(/\./g); + + if (dots && dots.length >= 2) { + url = `http://${url}`; + } + } + + if (options.tryConvertEncoding) { + try { + url = stringToUTF8String(url); + } catch (ex) {} + } + } + const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url); if (_isValidProtocol(absoluteUrl)) { @@ -2962,7 +2978,6 @@ exports.ChunkedStreamManager = ChunkedStreamManager; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.addDefaultProtocolToUrl = addDefaultProtocolToUrl; exports.collectActions = collectActions; exports.encodeToXmlString = encodeToXmlString; exports.escapePDFName = escapePDFName; @@ -2975,8 +2990,8 @@ exports.parseXFAPath = parseXFAPath; exports.readInt8 = readInt8; exports.readUint16 = readUint16; exports.readUint32 = readUint32; +exports.recoverJsURL = recoverJsURL; exports.toRomanNumerals = toRomanNumerals; -exports.tryConvertUrlEncoding = tryConvertUrlEncoding; exports.validateCSSFont = validateCSSFont; exports.XRefParseException = exports.XRefEntryException = exports.ParserEOFException = exports.MissingDataException = void 0; @@ -3368,16 +3383,26 @@ function validateCSSFont(cssFontInfo) { return true; } -function addDefaultProtocolToUrl(url) { - return url.startsWith("www.") ? `http://${url}` : url; -} +function recoverJsURL(str) { + const URL_OPEN_METHODS = ["app.launchURL", "window.open", "xfa.host.gotoURL"]; + const regex = new RegExp("^\\s*(" + URL_OPEN_METHODS.join("|").split(".").join("\\.") + ")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))", "i"); + const jsUrl = regex.exec(str); -function tryConvertUrlEncoding(url) { - try { - return (0, _util.stringToUTF8String)(url); - } catch (e) { - return url; + if (jsUrl && jsUrl[2]) { + const url = jsUrl[2]; + let newWindow = false; + + if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") { + newWindow = true; + } + + return { + url, + newWindow + }; } + + return null; } /***/ }), @@ -5978,6 +6003,8 @@ var _default_appearance = __w_pdfjs_require__(23); var _primitives = __w_pdfjs_require__(5); +var _bidi = __w_pdfjs_require__(59); + var _catalog = __w_pdfjs_require__(64); var _colorspace = __w_pdfjs_require__(24); @@ -6134,13 +6161,13 @@ class AnnotationFactory { exports.AnnotationFactory = AnnotationFactory; -function getRgbColor(color) { - const rgbColor = new Uint8ClampedArray(3); - +function getRgbColor(color, defaultColor = new Uint8ClampedArray(3)) { if (!Array.isArray(color)) { - return rgbColor; + return defaultColor; } + const rgbColor = defaultColor || new Uint8ClampedArray(3); + switch (color.length) { case 0: return null; @@ -6161,7 +6188,7 @@ function getRgbColor(color) { return rgbColor; default: - return rgbColor; + return defaultColor; } } @@ -6229,6 +6256,7 @@ function getTransformMatrix(rect, bbox, matrix) { class Annotation { constructor(params) { const dict = params.dict; + this.setTitle(dict.get("T")); this.setContents(dict.get("Contents")); this.setModificationDate(dict.get("M")); this.setFlags(dict.get("F")); @@ -6236,6 +6264,7 @@ class Annotation { this.setColor(dict.getArray("C")); this.setBorderStyle(dict); this.setAppearance(dict); + this.setBorderAndBackgroundColors(dict.get("MK")); this._streams = []; if (this.appearance) { @@ -6246,7 +6275,9 @@ class Annotation { annotationFlags: this.flags, borderStyle: this.borderStyle, color: this.color, - contents: this.contents, + backgroundColor: this.backgroundColor, + borderColor: this.borderColor, + contentsObj: this._contents, hasAppearance: !!this.appearance, id: params.id, modificationDate: this.modificationDate, @@ -6335,8 +6366,21 @@ class Annotation { return this._isPrintable(this.flags); } + _parseStringHelper(data) { + const str = typeof data === "string" ? (0, _util.stringToPDFString)(data) : ""; + const dir = str && (0, _bidi.bidi)(str).dir === "rtl" ? "rtl" : "ltr"; + return { + str, + dir + }; + } + + setTitle(title) { + this._title = this._parseStringHelper(title); + } + setContents(contents) { - this.contents = (0, _util.stringToPDFString)(contents || ""); + this._contents = this._parseStringHelper(contents); } setModificationDate(modificationDate) { @@ -6363,6 +6407,15 @@ class Annotation { this.color = getRgbColor(color); } + setBorderAndBackgroundColors(mk) { + if (mk instanceof _primitives.Dict) { + this.borderColor = getRgbColor(mk.getArray("BC"), null); + this.backgroundColor = getRgbColor(mk.getArray("BG"), null); + } else { + this.borderColor = this.backgroundColor = null; + } + } + setBorderStyle(borderStyle) { this.borderStyle = new AnnotationBorderStyle(); @@ -6476,6 +6529,8 @@ class Annotation { id: this.data.id, actions: this.data.actions, name: this.data.fieldName, + strokeColor: this.data.borderColor, + fillColor: this.data.backgroundColor, type: "", kidIds: this.data.kidIds, page: this.data.pageIndex @@ -6654,9 +6709,10 @@ class MarkupAnnotation extends Annotation { if (this.data.replyType === _util.AnnotationReplyType.GROUP) { const parent = dict.get("IRT"); - this.data.title = (0, _util.stringToPDFString)(parent.get("T") || ""); + this.setTitle(parent.get("T")); + this.data.titleObj = this._title; this.setContents(parent.get("Contents")); - this.data.contents = this.contents; + this.data.contentsObj = this._contents; if (!parent.has("CreationDate")) { this.data.creationDate = null; @@ -6681,7 +6737,7 @@ class MarkupAnnotation extends Annotation { this.data.color = this.color; } } else { - this.data.title = (0, _util.stringToPDFString)(dict.get("T") || ""); + this.data.titleObj = this._title; this.setCreationDate(dict.get("CreationDate")); this.data.creationDate = this.creationDate; this.data.hasPopup = dict.has("Popup"); @@ -7318,6 +7374,8 @@ class TextWidgetAnnotation extends WidgetAnnotation { rect: this.data.rect, actions: this.data.actions, page: this.data.pageIndex, + strokeColor: this.data.borderColor, + fillColor: this.data.backgroundColor, type: "text" }; } @@ -7345,39 +7403,41 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { } } - getOperatorList(evaluator, task, renderForms, annotationStorage) { + async getOperatorList(evaluator, task, renderForms, annotationStorage) { if (this.data.pushButton) { return super.getOperatorList(evaluator, task, false, annotationStorage); } + let value = null; + if (annotationStorage) { const storageEntry = annotationStorage.get(this.data.id); - const value = storageEntry && storageEntry.value; + value = storageEntry ? storageEntry.value : null; + } - if (value === undefined) { + if (value === null) { + if (this.appearance) { return super.getOperatorList(evaluator, task, renderForms, annotationStorage); } - let appearance; - - if (value) { - appearance = this.checkedAppearance; + if (this.data.checkBox) { + value = this.data.fieldValue === this.data.exportValue; } else { - appearance = this.uncheckedAppearance; + value = this.data.fieldValue === this.data.buttonValue; } - - if (appearance) { - const savedAppearance = this.appearance; - this.appearance = appearance; - const operatorList = super.getOperatorList(evaluator, task, renderForms, annotationStorage); - this.appearance = savedAppearance; - return operatorList; - } - - return Promise.resolve(new _operator_list.OperatorList()); } - return super.getOperatorList(evaluator, task, renderForms, annotationStorage); + const appearance = value ? this.checkedAppearance : this.uncheckedAppearance; + + if (appearance) { + const savedAppearance = this.appearance; + this.appearance = appearance; + const operatorList = super.getOperatorList(evaluator, task, renderForms, annotationStorage); + this.appearance = savedAppearance; + return operatorList; + } + + return new _operator_list.OperatorList(); } async save(evaluator, task, annotationStorage) { @@ -7404,7 +7464,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { return null; } - const defaultValue = this.data.fieldValue && this.data.fieldValue !== "Off"; + const defaultValue = this.data.fieldValue === this.data.exportValue; if (defaultValue === value) { return null; @@ -7523,6 +7583,51 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { return newRefs; } + _getDefaultCheckedAppearance(params, type) { + const width = this.data.rect[2] - this.data.rect[0]; + const height = this.data.rect[3] - this.data.rect[1]; + const bbox = [0, 0, width, height]; + const FONT_RATIO = 0.8; + const fontSize = Math.min(width, height) * FONT_RATIO; + let metrics, char; + + if (type === "check") { + metrics = { + width: 0.755 * fontSize, + height: 0.705 * fontSize + }; + char = "\x33"; + } else if (type === "disc") { + metrics = { + width: 0.791 * fontSize, + height: 0.705 * fontSize + }; + char = "\x6C"; + } else { + (0, _util.unreachable)(`_getDefaultCheckedAppearance - unsupported type: ${type}`); + } + + const xShift = (width - metrics.width) / 2; + const yShift = (height - metrics.height) / 2; + const appearance = `q BT /PdfJsZaDb ${fontSize} Tf 0 g ${xShift} ${yShift} Td (${char}) Tj ET Q`; + const appearanceStreamDict = new _primitives.Dict(params.xref); + appearanceStreamDict.set("FormType", 1); + appearanceStreamDict.set("Subtype", _primitives.Name.get("Form")); + appearanceStreamDict.set("Type", _primitives.Name.get("XObject")); + appearanceStreamDict.set("BBox", bbox); + appearanceStreamDict.set("Matrix", [1, 0, 0, 1, 0, 0]); + appearanceStreamDict.set("Length", appearance.length); + const resources = new _primitives.Dict(params.xref); + const font = new _primitives.Dict(params.xref); + font.set("PdfJsZaDb", this.fallbackFontDict); + resources.set("Font", font); + appearanceStreamDict.set("Resources", resources); + this.checkedAppearance = new _stream.StringStream(appearance); + this.checkedAppearance.dict = appearanceStreamDict; + + this._streams.push(this.checkedAppearance); + } + _processCheckBox(params) { const customAppearance = params.dict.get("AP"); @@ -7542,25 +7647,39 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { this.data.fieldValue = asValue; } + const yes = this.data.fieldValue !== null && this.data.fieldValue !== "Off" ? this.data.fieldValue : "Yes"; const exportValues = normalAppearance.getKeys(); - if (!exportValues.includes("Off")) { - exportValues.push("Off"); + if (exportValues.length === 0) { + exportValues.push("Off", yes); + } else if (exportValues.length === 1) { + if (exportValues[0] === "Off") { + exportValues.push(yes); + } else { + exportValues.unshift("Off"); + } + } else if (exportValues.includes(yes)) { + exportValues.length = 0; + exportValues.push("Off", yes); + } else { + const otherYes = exportValues.find(v => v !== "Off"); + exportValues.length = 0; + exportValues.push("Off", otherYes); } if (!exportValues.includes(this.data.fieldValue)) { - this.data.fieldValue = null; + this.data.fieldValue = "Off"; } - if (exportValues.length !== 2) { - return; - } - - this.data.exportValue = exportValues[0] === "Off" ? exportValues[1] : exportValues[0]; - this.checkedAppearance = normalAppearance.get(this.data.exportValue); + this.data.exportValue = exportValues[1]; + this.checkedAppearance = normalAppearance.get(this.data.exportValue) || null; this.uncheckedAppearance = normalAppearance.get("Off") || null; - this._streams.push(this.checkedAppearance); + if (this.checkedAppearance) { + this._streams.push(this.checkedAppearance); + } else { + this._getDefaultCheckedAppearance(params, "check"); + } if (this.uncheckedAppearance) { this._streams.push(this.uncheckedAppearance); @@ -7601,10 +7720,14 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { } } - this.checkedAppearance = normalAppearance.get(this.data.buttonValue); + this.checkedAppearance = normalAppearance.get(this.data.buttonValue) || null; this.uncheckedAppearance = normalAppearance.get("Off") || null; - this._streams.push(this.checkedAppearance); + if (this.checkedAppearance) { + this._streams.push(this.checkedAppearance); + } else { + this._getDefaultCheckedAppearance(params, "disc"); + } if (this.uncheckedAppearance) { this._streams.push(this.uncheckedAppearance); @@ -7651,6 +7774,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation { hidden: this.data.hidden, actions: this.data.actions, page: this.data.pageIndex, + strokeColor: this.data.borderColor, + fillColor: this.data.backgroundColor, type }; } @@ -7715,6 +7840,8 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation { actions: this.data.actions, items: this.data.options, page: this.data.pageIndex, + strokeColor: this.data.borderColor, + fillColor: this.data.backgroundColor, type }; } @@ -7834,8 +7961,10 @@ class PopupAnnotation extends Annotation { } } - this.data.title = (0, _util.stringToPDFString)(parentItem.get("T") || ""); - this.data.contents = (0, _util.stringToPDFString)(parentItem.get("Contents") || ""); + this.setTitle(parentItem.get("T")); + this.data.titleObj = this._title; + this.setContents(parentItem.get("Contents")); + this.data.contentsObj = this._contents; } } @@ -7862,7 +7991,7 @@ class LineAnnotation extends MarkupAnnotation { interiorColor = parameters.dict.getArray("IC"); if (interiorColor) { - interiorColor = getRgbColor(interiorColor); + interiorColor = getRgbColor(interiorColor, null); fillColor = interiorColor ? Array.from(interiorColor).map(c => c / 255) : null; } @@ -7904,7 +8033,7 @@ class SquareAnnotation extends MarkupAnnotation { interiorColor = parameters.dict.getArray("IC"); if (interiorColor) { - interiorColor = getRgbColor(interiorColor); + interiorColor = getRgbColor(interiorColor, null); fillColor = interiorColor ? Array.from(interiorColor).map(c => c / 255) : null; } @@ -7950,7 +8079,7 @@ class CircleAnnotation extends MarkupAnnotation { let interiorColor = parameters.dict.getArray("IC"); if (interiorColor) { - interiorColor = getRgbColor(interiorColor); + interiorColor = getRgbColor(interiorColor, null); fillColor = interiorColor ? Array.from(interiorColor).map(c => c / 255) : null; } @@ -9505,6 +9634,8 @@ var _image_utils = __w_pdfjs_require__(58); var _stream = __w_pdfjs_require__(10); +var _base_stream = __w_pdfjs_require__(6); + var _bidi = __w_pdfjs_require__(59); var _colorspace = __w_pdfjs_require__(24); @@ -12250,7 +12381,7 @@ class PartialEvaluator { const cidToGidMap = dict.get("CIDToGIDMap"); - if ((0, _primitives.isStream)(cidToGidMap)) { + if (cidToGidMap instanceof _base_stream.BaseStream) { cidToGidBytes = cidToGidMap.getBytes(); } } @@ -12850,6 +12981,16 @@ class PartialEvaluator { hash.update(widthsBuf.join()); } + + const cidToGidMap = dict.getRaw("CIDToGIDMap") || baseDict.getRaw("CIDToGIDMap"); + + if (cidToGidMap instanceof _primitives.Name) { + hash.update(cidToGidMap.name); + } else if (cidToGidMap instanceof _primitives.Ref) { + hash.update(cidToGidMap.toString()); + } else if (cidToGidMap instanceof _base_stream.BaseStream) { + hash.update(cidToGidMap.peekBytes()); + } } } @@ -12902,6 +13043,7 @@ class PartialEvaluator { loadedName: baseDict.loadedName, widths: metrics.widths, defaultWidth: metrics.defaultWidth, + isSimulatedFlags: true, flags, firstChar, lastChar, @@ -15857,8 +15999,6 @@ class Lexer { if (strBuf.length > 127) { (0, _util.warn)(`Name token is longer than allowed by the spec: ${strBuf.length}`); - } else if (strBuf.length === 0) { - (0, _util.warn)("Name token is empty."); } return _primitives.Name.get(strBuf.join("")); @@ -24516,8 +24656,8 @@ var _type1_font = __w_pdfjs_require__(53); const PRIVATE_USE_AREAS = [[0xe000, 0xf8ff], [0x100000, 0x10fffd]]; const PDF_GLYPH_SPACE_UNITS = 1000; -const EXPORT_DATA_PROPERTIES = ["ascent", "bbox", "black", "bold", "charProcOperatorList", "composite", "cssFontInfo", "data", "defaultVMetrics", "defaultWidth", "descent", "fallbackName", "fontMatrix", "fontType", "isMonospace", "isSerifFont", "isType3Font", "italic", "loadedName", "mimetype", "missingFile", "name", "remeasure", "subtype", "type", "vertical"]; -const EXPORT_DATA_EXTRA_PROPERTIES = ["cMap", "defaultEncoding", "differences", "isSymbolicFont", "seacMap", "toFontChar", "toUnicode", "vmetrics", "widths"]; +const EXPORT_DATA_PROPERTIES = ["ascent", "bbox", "black", "bold", "charProcOperatorList", "composite", "cssFontInfo", "data", "defaultVMetrics", "defaultWidth", "descent", "fallbackName", "fontMatrix", "fontType", "isType3Font", "italic", "loadedName", "mimetype", "missingFile", "name", "remeasure", "subtype", "type", "vertical"]; +const EXPORT_DATA_EXTRA_PROPERTIES = ["cMap", "defaultEncoding", "differences", "isMonospace", "isSerifFont", "isSymbolicFont", "seacMap", "toFontChar", "toUnicode", "vmetrics", "widths"]; function adjustWidths(properties) { if (!properties.fontMatrix) { @@ -24763,6 +24903,25 @@ function buildToFontChar(encoding, glyphsUnicodeMap, differences) { return toFontChar; } +function convertCidString(charCode, cid, shouldThrow = false) { + switch (cid.length) { + case 1: + return cid.charCodeAt(0); + + case 2: + return cid.charCodeAt(0) << 8 | cid.charCodeAt(1); + } + + const msg = `Unsupported CID string (charCode ${charCode}): "${cid}".`; + + if (shouldThrow) { + throw new _util.FormatError(msg); + } + + (0, _util.warn)(msg); + return cid; +} + function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId) { const newMap = Object.create(null); const toFontChar = []; @@ -25115,7 +25274,21 @@ class Font { this.cssFontInfo = properties.cssFontInfo; this._charsCache = Object.create(null); this._glyphCache = Object.create(null); - this.isSerifFont = !!(properties.flags & _fonts_utils.FontFlags.Serif); + let isSerifFont = !!(properties.flags & _fonts_utils.FontFlags.Serif); + + if (!isSerifFont && !properties.isSimulatedFlags) { + const baseName = name.replace(/[,_]/g, "-").split("-")[0], + serifFonts = (0, _standard_fonts.getSerifFonts)(); + + for (const namePart of baseName.split("+")) { + if (serifFonts[namePart]) { + isSerifFont = true; + break; + } + } + } + + this.isSerifFont = isSerifFont; this.isSymbolicFont = !!(properties.flags & _fonts_utils.FontFlags.Symbolic); this.isMonospace = !!(properties.flags & _fonts_utils.FontFlags.FixedPitch); let type = properties.type; @@ -25155,7 +25328,7 @@ class Font { return; } - this.cidEncoding = properties.cidEncoding; + this.cidEncoding = properties.cidEncoding || ""; this.vertical = !!properties.vertical; if (this.vertical) { @@ -26670,6 +26843,10 @@ class Font { const cidToGidMap = properties.cidToGidMap || []; const isCidToGidMapEmpty = cidToGidMap.length === 0; properties.cMap.forEach(function (charCode, cid) { + if (typeof cid === "string") { + cid = convertCidString(charCode, cid, true); + } + if (cid > 0xffff) { throw new _util.FormatError("Max size of CID is 65,535"); } @@ -26995,6 +27172,10 @@ class Font { if (this.composite && this.cMap.contains(glyphUnicode)) { charcode = this.cMap.lookup(glyphUnicode); + + if (typeof charcode === "string") { + charcode = convertCidString(glyphUnicode, charcode); + } } if (!charcode && this.toUnicode) { @@ -27022,6 +27203,10 @@ class Font { if (this.cMap && this.cMap.contains(charcode)) { widthCode = this.cMap.lookup(charcode); + + if (typeof widthCode === "string") { + widthCode = convertCidString(charcode, widthCode); + } } width = this.widths[widthCode]; @@ -29315,6 +29500,7 @@ const getSerifFonts = (0, _core_utils.getLookupTableFactory)(function (t) { t.Joanna = true; t.Korinna = true; t.Lexicon = true; + t.LiberationSerif = true; t["Liberation Serif"] = true; t["Linux Libertine"] = true; t.Literaturnaya = true; @@ -35897,7 +36083,7 @@ function createBidiText(str, isLTR, vertical = false) { const chars = []; const types = []; -function bidi(str, startLevel, vertical) { +function bidi(str, startLevel = -1, vertical = false) { let isLTR = true; const strLength = str.length; @@ -40560,10 +40746,10 @@ Object.defineProperty(exports, "__esModule", ({ })); exports.Catalog = void 0; -var _core_utils = __w_pdfjs_require__(9); - var _primitives = __w_pdfjs_require__(5); +var _core_utils = __w_pdfjs_require__(9); + var _util = __w_pdfjs_require__(2); var _name_number_tree = __w_pdfjs_require__(65); @@ -41925,13 +42111,32 @@ class Catalog { const actionName = actionType.name; switch (actionName) { + case "ResetForm": + const flags = action.get("Flags"); + const include = (((0, _util.isNum)(flags) ? flags : 0) & 1) === 0; + const fields = []; + const refs = []; + + for (const obj of action.get("Fields") || []) { + if ((0, _primitives.isRef)(obj)) { + refs.push(obj.toString()); + } else if ((0, _util.isString)(obj)) { + fields.push((0, _util.stringToPDFString)(obj)); + } + } + + resultObj.resetForm = { + fields, + refs, + include + }; + break; + case "URI": url = action.get("URI"); - if ((0, _primitives.isName)(url)) { + if (url instanceof _primitives.Name) { url = "/" + url.name; - } else if ((0, _util.isString)(url)) { - url = (0, _core_utils.addDefaultProtocolToUrl)(url); } break; @@ -41995,24 +42200,16 @@ class Catalog { js = jsAction; } - if (js) { - const URL_OPEN_METHODS = ["app.launchURL", "window.open"]; - const regex = new RegExp("^\\s*(" + URL_OPEN_METHODS.join("|").split(".").join("\\.") + ")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))", "i"); - const jsUrl = regex.exec((0, _util.stringToPDFString)(js)); + const jsURL = js && (0, _core_utils.recoverJsURL)((0, _util.stringToPDFString)(js)); - if (jsUrl && jsUrl[2]) { - url = jsUrl[2]; - - if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") { - resultObj.newWindow = true; - } - - break; - } + if (jsURL) { + url = jsURL.url; + resultObj.newWindow = jsURL.newWindow; + break; } default: - if (actionName === "JavaScript" || actionName === "ResetForm" || actionName === "SubmitForm") { + if (actionName === "JavaScript" || actionName === "SubmitForm") { break; } @@ -42024,8 +42221,10 @@ class Catalog { } if ((0, _util.isString)(url)) { - url = (0, _core_utils.tryConvertUrlEncoding)(url); - const absoluteUrl = (0, _util.createValidAbsoluteUrl)(url, docBaseUrl); + const absoluteUrl = (0, _util.createValidAbsoluteUrl)(url, docBaseUrl, { + addDefaultProtocol: true, + tryConvertEncoding: true + }); if (absoluteUrl) { resultObj.url = absoluteUrl.href; @@ -47946,6 +48145,14 @@ class Binder { return [occur.min, max]; } + _setAndBind(formNode, dataNode) { + this._setProperties(formNode, dataNode); + + this._bindItems(formNode, dataNode); + + this._bindElement(formNode, dataNode); + } + _bindElement(formNode, dataNode) { const uselessNodes = []; @@ -47987,7 +48194,7 @@ class Binder { if (child.bind) { switch (child.bind.match) { case "none": - this._bindElement(child, dataNode); + this._setAndBind(child, dataNode); continue; @@ -47999,7 +48206,7 @@ class Binder { if (!child.bind.ref) { (0, _util.warn)(`XFA - ref is empty in node ${child[_xfa_object.$nodeName]}.`); - this._bindElement(child, dataNode); + this._setAndBind(child, dataNode); continue; } @@ -48032,7 +48239,7 @@ class Binder { match[_xfa_object.$consumed] = true; } - this._bindElement(child, match); + this._setAndBind(child, match); continue; } else { @@ -48054,7 +48261,7 @@ class Binder { } } else { if (!child.name) { - this._bindElement(child, dataNode); + this._setAndBind(child, dataNode); continue; } @@ -48087,11 +48294,7 @@ class Binder { dataNode[_xfa_object.$appendChild](match); - this._setProperties(child, match); - - this._bindItems(child, match); - - this._bindElement(child, match); + this._setAndBind(child, match); continue; } @@ -48107,11 +48310,7 @@ class Binder { if (match) { this._bindOccurrences(child, match, picture); } else if (min > 0) { - this._setProperties(child, dataNode); - - this._bindItems(child, dataNode); - - this._bindElement(child, dataNode); + this._setAndBind(child, dataNode); } else { uselessNodes.push(child); } @@ -48149,6 +48348,8 @@ var _util = __w_pdfjs_require__(2); var _fonts = __w_pdfjs_require__(83); +var _core_utils = __w_pdfjs_require__(9); + var _som = __w_pdfjs_require__(78); const TEMPLATE_NS_ID = _namespaces.NamespaceIds.template.id; @@ -48966,7 +49167,11 @@ class Button extends _xfa_object.XFAObject { } [_xfa_object.$toHTML](availableSpace) { - return _utils.HTMLResult.success({ + const parent = this[_xfa_object.$getParent](); + + const grandpa = parent[_xfa_object.$getParent](); + + const htmlButton = { name: "button", attributes: { id: this[_xfa_object.$uid], @@ -48974,7 +49179,39 @@ class Button extends _xfa_object.XFAObject { 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); } } @@ -50576,7 +50813,13 @@ class Field extends _xfa_object.XFAObject { ui.attributes.style = Object.create(null); } + let aElement = null; + if (this.ui.button) { + if (ui.children.length === 1) { + [aElement] = ui.children.splice(0, 1); + } + Object.assign(ui.attributes.style, borderStyle); } else { Object.assign(style, borderStyle); @@ -50639,6 +50882,10 @@ class Field extends _xfa_object.XFAObject { } } + if (aElement) { + ui.children.push(aElement); + } + if (!caption) { if (ui.attributes.class) { ui.attributes.class.push("xfaLeft"); @@ -52415,12 +52662,6 @@ class Subform extends _xfa_object.XFAObject { return false; } - const contentArea = this[_xfa_object.$getTemplateRoot]()[_xfa_object.$extra].currentContentArea; - - if (this.overflow && this.overflow[_xfa_object.$getExtra]().target === contentArea) { - return false; - } - if (this[_xfa_object.$extra]._isSplittable !== undefined) { return this[_xfa_object.$extra]._isSplittable; } @@ -52541,13 +52782,8 @@ class Subform extends _xfa_object.XFAObject { const root = this[_xfa_object.$getTemplateRoot](); - const currentContentArea = root[_xfa_object.$extra].currentContentArea; const savedNoLayoutFailure = root[_xfa_object.$extra].noLayoutFailure; - if (this.overflow) { - root[_xfa_object.$extra].noLayoutFailure = root[_xfa_object.$extra].noLayoutFailure || this.overflow[_xfa_object.$getExtra]().target === currentContentArea; - } - const isSplittable = this[_xfa_object.$isSplittable](); if (!isSplittable) { @@ -53025,6 +53261,7 @@ class Template extends _xfa_object.XFAObject { overflowExtra.addLeader = overflowExtra.leader !== null; overflowExtra.addTrailer = overflowExtra.trailer !== null; flush(i); + const currentIndex = i; i = Infinity; if (target instanceof PageArea) { @@ -53033,7 +53270,11 @@ class Template extends _xfa_object.XFAObject { const index = contentAreas.findIndex(e => e === target); if (index !== -1) { - i = index - 1; + if (index > currentIndex) { + i = index - 1; + } else { + startIndex = index; + } } else { targetPageArea = target[_xfa_object.$getParent](); startIndex = targetPageArea.contentArea.children.findIndex(e => e === target); @@ -54355,6 +54596,7 @@ exports.computeBbox = computeBbox; exports.createWrapper = createWrapper; exports.fixDimensions = fixDimensions; exports.fixTextIndent = fixTextIndent; +exports.fixURL = fixURL; exports.isPrintOnly = isPrintOnly; exports.layoutClass = layoutClass; exports.layoutNode = layoutNode; @@ -54367,14 +54609,14 @@ exports.toStyle = toStyle; var _xfa_object = __w_pdfjs_require__(75); +var _util = __w_pdfjs_require__(2); + var _utils = __w_pdfjs_require__(76); var _fonts = __w_pdfjs_require__(83); var _text = __w_pdfjs_require__(84); -var _util = __w_pdfjs_require__(2); - function measureToString(m) { if (typeof m === "string") { return "0px"; @@ -55012,6 +55254,14 @@ function setFontFamily(xfaFont, node, fontFinder, style) { } } +function fixURL(str) { + const absoluteUrl = (0, _util.createValidAbsoluteUrl)(str, null, { + addDefaultProtocol: true, + tryConvertEncoding: true + }); + return absoluteUrl ? absoluteUrl.href : null; +} + /***/ }), /* 83 */ /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => { @@ -58693,14 +58943,10 @@ var _xfa_object = __w_pdfjs_require__(75); var _namespaces = __w_pdfjs_require__(77); -var _core_utils = __w_pdfjs_require__(9); - var _html_utils = __w_pdfjs_require__(82); var _utils = __w_pdfjs_require__(76); -var _util = __w_pdfjs_require__(2); - const XHTML_NS_ID = _namespaces.NamespaceIds.xhtml.id; const VALID_STYLES = new Set(["color", "font", "font-family", "font-size", "font-stretch", "font-style", "font-weight", "margin", "margin-bottom", "margin-left", "margin-right", "margin-top", "letter-spacing", "line-height", "orphans", "page-break-after", "page-break-before", "page-break-inside", "tab-interval", "tab-stop", "text-align", "text-decoration", "text-indent", "vertical-align", "widows", "kerning-mode", "xfa-font-horizontal-scale", "xfa-font-vertical-scale", "xfa-spacerun", "xfa-tab-stops"]); const StyleMapping = new Map([["page-break-after", "breakAfter"], ["page-break-before", "breakBefore"], ["page-break-inside", "breakInside"], ["kerning-mode", value => value === "none" ? "none" : "normal"], ["xfa-font-horizontal-scale", value => `scaleX(${Math.max(0, Math.min(parseInt(value) / 100)).toFixed(2)})`], ["xfa-font-vertical-scale", value => `scaleY(${Math.max(0, Math.min(parseInt(value) / 100)).toFixed(2)})`], ["xfa-spacerun", ""], ["xfa-tab-stops", ""], ["font-size", (value, original) => { @@ -58935,19 +59181,7 @@ class XhtmlObject extends _xfa_object.XmlObject { class A extends XhtmlObject { constructor(attributes) { super(attributes, "a"); - let href = ""; - - if (typeof attributes.href === "string") { - let url = (0, _core_utils.addDefaultProtocolToUrl)(attributes.href); - url = (0, _core_utils.tryConvertUrlEncoding)(url); - const absoluteUrl = (0, _util.createValidAbsoluteUrl)(url); - - if (absoluteUrl) { - href = absoluteUrl.href; - } - } - - this.href = href; + this.href = (0, _html_utils.fixURL)(attributes.href) || ""; } } @@ -60250,10 +60484,10 @@ class MessageHandler { } sendWithStream(actionName, data, queueingStrategy, transfers) { - const streamId = this.streamId++; - const sourceName = this.sourceName; - const targetName = this.targetName; - const comObj = this.comObj; + const streamId = this.streamId++, + sourceName = this.sourceName, + targetName = this.targetName, + comObj = this.comObj; return new ReadableStream({ start: controller => { const startCapability = (0, _util.createPromiseCapability)(); @@ -60306,12 +60540,12 @@ class MessageHandler { } _createStreamSink(data) { - const self = this; - const action = this.actionHandler[data.action]; - const streamId = data.streamId; - const sourceName = this.sourceName; - const targetName = data.sourceName; - const comObj = this.comObj; + const streamId = data.streamId, + sourceName = this.sourceName, + targetName = data.sourceName, + comObj = this.comObj; + const self = this, + action = this.actionHandler[data.action]; const streamSink = { enqueue(chunk, size = 1, transfers) { if (this.isCancelled) { @@ -60399,32 +60633,34 @@ class MessageHandler { } _processStreamMessage(data) { - const streamId = data.streamId; - const sourceName = this.sourceName; - const targetName = data.sourceName; - const comObj = this.comObj; + const streamId = data.streamId, + sourceName = this.sourceName, + targetName = data.sourceName, + comObj = this.comObj; + const streamController = this.streamControllers[streamId], + streamSink = this.streamSinks[streamId]; switch (data.stream) { case StreamKind.START_COMPLETE: if (data.success) { - this.streamControllers[streamId].startCall.resolve(); + streamController.startCall.resolve(); } else { - this.streamControllers[streamId].startCall.reject(wrapReason(data.reason)); + streamController.startCall.reject(wrapReason(data.reason)); } break; case StreamKind.PULL_COMPLETE: if (data.success) { - this.streamControllers[streamId].pullCall.resolve(); + streamController.pullCall.resolve(); } else { - this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason)); + streamController.pullCall.reject(wrapReason(data.reason)); } break; case StreamKind.PULL: - if (!this.streamSinks[streamId]) { + if (!streamSink) { comObj.postMessage({ sourceName, targetName, @@ -60435,16 +60671,13 @@ class MessageHandler { break; } - if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) { - this.streamSinks[streamId].sinkCapability.resolve(); + if (streamSink.desiredSize <= 0 && data.desiredSize > 0) { + streamSink.sinkCapability.resolve(); } - this.streamSinks[streamId].desiredSize = data.desiredSize; - const { - onPull - } = this.streamSinks[streamId]; + streamSink.desiredSize = data.desiredSize; new Promise(function (resolve) { - resolve(onPull && onPull()); + resolve(streamSink.onPull && streamSink.onPull()); }).then(function () { comObj.postMessage({ sourceName, @@ -60465,58 +60698,55 @@ class MessageHandler { break; case StreamKind.ENQUEUE: - (0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller"); + (0, _util.assert)(streamController, "enqueue should have stream controller"); - if (this.streamControllers[streamId].isClosed) { + if (streamController.isClosed) { break; } - this.streamControllers[streamId].controller.enqueue(data.chunk); + streamController.controller.enqueue(data.chunk); break; case StreamKind.CLOSE: - (0, _util.assert)(this.streamControllers[streamId], "close should have stream controller"); + (0, _util.assert)(streamController, "close should have stream controller"); - if (this.streamControllers[streamId].isClosed) { + if (streamController.isClosed) { break; } - this.streamControllers[streamId].isClosed = true; - this.streamControllers[streamId].controller.close(); + streamController.isClosed = true; + streamController.controller.close(); - this._deleteStreamController(streamId); + this._deleteStreamController(streamController, streamId); break; case StreamKind.ERROR: - (0, _util.assert)(this.streamControllers[streamId], "error should have stream controller"); - this.streamControllers[streamId].controller.error(wrapReason(data.reason)); + (0, _util.assert)(streamController, "error should have stream controller"); + streamController.controller.error(wrapReason(data.reason)); - this._deleteStreamController(streamId); + this._deleteStreamController(streamController, streamId); break; case StreamKind.CANCEL_COMPLETE: if (data.success) { - this.streamControllers[streamId].cancelCall.resolve(); + streamController.cancelCall.resolve(); } else { - this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason)); + streamController.cancelCall.reject(wrapReason(data.reason)); } - this._deleteStreamController(streamId); + this._deleteStreamController(streamController, streamId); break; case StreamKind.CANCEL: - if (!this.streamSinks[streamId]) { + if (!streamSink) { break; } - const { - onCancel - } = this.streamSinks[streamId]; new Promise(function (resolve) { - resolve(onCancel && onCancel(wrapReason(data.reason))); + resolve(streamSink.onCancel && streamSink.onCancel(wrapReason(data.reason))); }).then(function () { comObj.postMessage({ sourceName, @@ -60534,8 +60764,8 @@ class MessageHandler { reason: wrapReason(reason) }); }); - this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason)); - this.streamSinks[streamId].isCancelled = true; + streamSink.sinkCapability.reject(wrapReason(data.reason)); + streamSink.isCancelled = true; delete this.streamSinks[streamId]; break; @@ -60544,10 +60774,8 @@ class MessageHandler { } } - async _deleteStreamController(streamId) { - await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) { - return capability && capability.promise; - })); + async _deleteStreamController(streamController, streamId) { + await Promise.allSettled([streamController.startCall && streamController.startCall.promise, streamController.pullCall && streamController.pullCall.promise, streamController.cancelCall && streamController.cancelCall.promise]); delete this.streamControllers[streamId]; } @@ -60763,8 +60991,8 @@ Object.defineProperty(exports, "WorkerMessageHandler", ({ var _worker = __w_pdfjs_require__(1); -const pdfjsVersion = '2.11.298'; -const pdfjsBuild = 'd370a281c'; +const pdfjsVersion = '2.12.16'; +const pdfjsBuild = '394596560'; })(); /******/ return __webpack_exports__; diff --git a/toolkit/components/pdfjs/content/web/viewer.css b/toolkit/components/pdfjs/content/web/viewer.css index f743194e0902..e327295d881f 100644 --- a/toolkit/components/pdfjs/content/web/viewer.css +++ b/toolkit/components/pdfjs/content/web/viewer.css @@ -87,6 +87,10 @@ } +:root { + --annotation-unfocused-field-background: url("data:image/svg+xml;charset=UTF-8,"); +} + .annotationLayer section { position: absolute; text-align: initial; @@ -119,7 +123,7 @@ .annotationLayer .choiceWidgetAnnotation select, .annotationLayer .buttonWidgetAnnotation.checkBox input, .annotationLayer .buttonWidgetAnnotation.radioButton input { - background-color: rgba(0, 54, 255, 0.13); + background-image: var(--annotation-unfocused-field-background); border: 1px solid transparent; box-sizing: border-box; font-size: 9px; @@ -174,6 +178,8 @@ .annotationLayer .choiceWidgetAnnotation select :focus, .annotationLayer .buttonWidgetAnnotation.checkBox :focus, .annotationLayer .buttonWidgetAnnotation.radioButton :focus { + background-image: none; + background-color: transparent; outline: auto; } @@ -290,7 +296,7 @@ :root { - --unfocused-field-background: url("data:image/svg+xml;charset=UTF-8,"); + --xfa-unfocused-field-background: url("data:image/svg+xml;charset=UTF-8,"); } .xfaLayer .highlight { @@ -478,7 +484,7 @@ flex: 1 1 auto; border: none; resize: none; - background-image: var(--unfocused-field-background); + background-image: var(--xfa-unfocused-field-background); } .xfaTop > .xfaTextfield, @@ -496,6 +502,11 @@ text-align: center; } +.xfaLink { + width: 100%; + height: 100%; +} + .xfaCheckbox, .xfaRadio { width: 100%; @@ -871,7 +882,6 @@ @media screen and (forced-colors: active) { :root { - --main-color: ButtonText; --button-hover-color: Highlight; --doorhanger-hover-bg-color: Highlight; --toolbar-icon-opacity: 1; diff --git a/toolkit/components/pdfjs/content/web/viewer.js b/toolkit/components/pdfjs/content/web/viewer.js index 0fa4fada1e81..4e4751b0a776 100644 --- a/toolkit/components/pdfjs/content/web/viewer.js +++ b/toolkit/components/pdfjs/content/web/viewer.js @@ -4045,7 +4045,7 @@ class PDFRenderingQueue { } } - getHighestPriority(visible, views, scrolledDown) { + getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) { const visibleViews = visible.views; const numVisible = visibleViews.length; @@ -4061,17 +4061,19 @@ class PDFRenderingQueue { } } - if (scrolledDown) { - const nextPageIndex = visible.last.id; + let preRenderIndex = scrolledDown ? visible.last.id : visible.first.id - 2; + let preRenderView = views[preRenderIndex]; - if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) { - return views[nextPageIndex]; - } - } else { - const previousPageIndex = visible.first.id - 2; + if (preRenderView && !this.isViewFinished(preRenderView)) { + return preRenderView; + } - if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) { - return views[previousPageIndex]; + if (preRenderExtra) { + preRenderIndex += scrolledDown ? 1 : -1; + preRenderView = views[preRenderIndex]; + + if (preRenderView && !this.isViewFinished(preRenderView)) { + return preRenderView; } } @@ -6693,6 +6695,8 @@ Object.defineProperty(exports, "__esModule", ({ })); exports.SimpleLinkService = exports.PDFLinkService = void 0; +var _pdfjsLib = __webpack_require__(4); + var _ui_utils = __webpack_require__(3); class PDFLinkService { @@ -6838,6 +6842,15 @@ class PDFLinkService { }); } + addLinkAttributes(link, url, newWindow = false) { + (0, _pdfjsLib.addLinkAttributes)(link, { + url, + target: newWindow ? _pdfjsLib.LinkTarget.BLANK : this.externalLinkTarget, + rel: this.externalLinkRel, + enabled: this.externalLinkEnabled + }); + } + getDestinationHash(dest) { if (typeof dest === "string") { if (dest.length > 0) { @@ -7086,10 +7099,7 @@ function isValidExplicitDestination(dest) { class SimpleLinkService { constructor() { - this.externalLinkTarget = null; - this.externalLinkRel = null; this.externalLinkEnabled = true; - this._ignoreDestinationZoom = false; } get pagesCount() { @@ -7112,6 +7122,13 @@ class SimpleLinkService { goToPage(val) {} + addLinkAttributes(link, url, newWindow = false) { + (0, _pdfjsLib.addLinkAttributes)(link, { + url, + enabled: this.externalLinkEnabled + }); + } + getDestinationHash(dest) { return "#"; } @@ -7149,10 +7166,10 @@ Object.defineProperty(exports, "__esModule", ({ })); exports.PDFOutlineViewer = void 0; -var _pdfjsLib = __webpack_require__(4); - var _base_tree_viewer = __webpack_require__(11); +var _pdfjsLib = __webpack_require__(4); + var _ui_utils = __webpack_require__(3); class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer { @@ -7221,12 +7238,7 @@ class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer { } = this; if (url) { - (0, _pdfjsLib.addLinkAttributes)(element, { - url, - target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget, - rel: linkService.externalLinkRel, - enabled: linkService.externalLinkEnabled - }); + linkService.addLinkAttributes(element, url, newWindow); return; } @@ -9682,7 +9694,7 @@ class BaseViewer { throw new Error("Cannot initialize BaseViewer."); } - const viewerVersion = '2.11.298'; + const viewerVersion = '2.12.16'; if (_pdfjsLib.version !== viewerVersion) { throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`); @@ -10633,7 +10645,8 @@ class BaseViewer { const visiblePages = currentlyVisiblePages || this._getVisiblePages(); const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down; - const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead); + const preRenderExtra = this._scrollMode === _ui_utils.ScrollMode.VERTICAL && this._spreadMode !== _ui_utils.SpreadMode.NONE && !this.isInPresentationMode; + const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra); if (pageView) { this._ensurePdfPageLoaded(pageView).then(() => { @@ -10686,7 +10699,8 @@ class BaseViewer { return new _xfa_layer_builder.XfaLayerBuilder({ pageDiv, pdfPage, - annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage + annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage, + linkService: this.linkService }); } @@ -12624,6 +12638,8 @@ Object.defineProperty(exports, "__esModule", ({ })); exports.XfaLayerBuilder = exports.DefaultXfaLayerFactory = void 0; +var _pdf_link_service = __webpack_require__(18); + var _pdfjsLib = __webpack_require__(4); class XfaLayerBuilder { @@ -12631,11 +12647,13 @@ class XfaLayerBuilder { pageDiv, pdfPage, annotationStorage, + linkService, xfaHtml }) { this.pageDiv = pageDiv; this.pdfPage = pdfPage; this.annotationStorage = annotationStorage; + this.linkService = linkService; this.xfaHtml = xfaHtml; this.div = null; this._cancelled = false; @@ -12651,6 +12669,7 @@ class XfaLayerBuilder { xfa: this.xfaHtml, page: null, annotationStorage: this.annotationStorage, + linkService: this.linkService, intent }; const div = document.createElement("div"); @@ -12677,6 +12696,7 @@ class XfaLayerBuilder { xfa, page: this.pdfPage, annotationStorage: this.annotationStorage, + linkService: this.linkService, intent }; @@ -12715,6 +12735,7 @@ class DefaultXfaLayerFactory { pageDiv, pdfPage, annotationStorage, + linkService: new _pdf_link_service.SimpleLinkService(), xfaHtml }); } @@ -14429,8 +14450,8 @@ var _app_options = __webpack_require__(1); var _app = __webpack_require__(2); -const pdfjsVersion = '2.11.298'; -const pdfjsBuild = 'd370a281c'; +const pdfjsVersion = '2.12.16'; +const pdfjsBuild = '394596560'; window.PDFViewerApplication = _app.PDFViewerApplication; window.PDFViewerApplicationOptions = _app_options.AppOptions; ; diff --git a/toolkit/components/pdfjs/moz.yaml b/toolkit/components/pdfjs/moz.yaml index 67f5291eb4a3..090ded9697eb 100644 --- a/toolkit/components/pdfjs/moz.yaml +++ b/toolkit/components/pdfjs/moz.yaml @@ -20,7 +20,7 @@ origin: # Human-readable identifier for this version/release # Generally "version NNN", "tag SSS", "bookmark SSS" - release: version 2.11.298 + release: version 2.12.16 # The package's license, where possible using the mnemonic from # https://spdx.org/licenses/