Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Mar 31, 2024
1 parent fffcaae commit 0797090
Show file tree
Hide file tree
Showing 39 changed files with 500 additions and 85 deletions.
129 changes: 108 additions & 21 deletions build/pdf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ class AnnotationElement {
container.tabIndex = DEFAULT_TAB_INDEX;
}
container.style.zIndex = this.parent.zIndex++;
if (this.data.popupRef) {
if (data.popupRef) {
container.setAttribute("aria-haspopup", "dialog");
}
if (data.alternativeText) {
container.title = data.alternativeText;
}
if (data.noRotate) {
container.classList.add("norotate");
}
Expand Down Expand Up @@ -878,9 +881,6 @@ class TextAnnotationElement extends AnnotationElement {
}
class WidgetAnnotationElement extends AnnotationElement {
render() {
if (this.data.alternativeText) {
this.container.title = this.data.alternativeText;
}
return this.container;
}
showElementAndHideCanvas(element) {
Expand Down Expand Up @@ -1481,9 +1481,6 @@ class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
render() {
const container = super.render();
container.classList.add("buttonWidgetAnnotation", "pushButton");
if (this.data.alternativeText) {
container.title = this.data.alternativeText;
}
const linkElement = container.lastChild;
if (this.enableScripting && this.hasJSActions && linkElement) {
this._setDefaultPropertiesFromJS(linkElement);
Expand Down Expand Up @@ -4592,7 +4589,7 @@ class InternalRenderTask {
}
}
const version = "4.1.0";
const build = "14307c0";
const build = "3d2eb36";

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });
Expand Down Expand Up @@ -8435,11 +8432,13 @@ var annotation_layer = __webpack_require__(976);



const EOL_PATTERN = /\r\n?|\n/g;
class FreeTextEditor extends editor_editor.AnnotationEditor {
#boundEditorDivBlur = this.editorDivBlur.bind(this);
#boundEditorDivFocus = this.editorDivFocus.bind(this);
#boundEditorDivInput = this.editorDivInput.bind(this);
#boundEditorDivKeydown = this.editorDivKeydown.bind(this);
#boundEditorDivPaste = this.editorDivPaste.bind(this);
#color;
#content = "";
#editorDivId = `${this.id}-editor`;
Expand Down Expand Up @@ -8592,6 +8591,7 @@ class FreeTextEditor extends editor_editor.AnnotationEditor {
this.editorDiv.addEventListener("focus", this.#boundEditorDivFocus);
this.editorDiv.addEventListener("blur", this.#boundEditorDivBlur);
this.editorDiv.addEventListener("input", this.#boundEditorDivInput);
this.editorDiv.addEventListener("paste", this.#boundEditorDivPaste);
}
disableEditMode() {
if (!this.isInEditMode()) {
Expand All @@ -8607,6 +8607,7 @@ class FreeTextEditor extends editor_editor.AnnotationEditor {
this.editorDiv.removeEventListener("focus", this.#boundEditorDivFocus);
this.editorDiv.removeEventListener("blur", this.#boundEditorDivBlur);
this.editorDiv.removeEventListener("input", this.#boundEditorDivInput);
this.editorDiv.removeEventListener("paste", this.#boundEditorDivPaste);
this.div.focus({
preventScroll: true
});
Expand Down Expand Up @@ -8648,10 +8649,8 @@ class FreeTextEditor extends editor_editor.AnnotationEditor {
#extractText() {
const buffer = [];
this.editorDiv.normalize();
const EOL_PATTERN = /\r\n?|\n/g;
for (const child of this.editorDiv.childNodes) {
const content = child.nodeType === Node.TEXT_NODE ? child.nodeValue : child.innerText;
buffer.push(content.replaceAll(EOL_PATTERN, ""));
buffer.push(FreeTextEditor.#getNodeContent(child));
}
return buffer.join("\n");
}
Expand Down Expand Up @@ -8821,6 +8820,85 @@ class FreeTextEditor extends editor_editor.AnnotationEditor {
}
return this.div;
}
static #getNodeContent(node) {
return (node.nodeType === Node.TEXT_NODE ? node.nodeValue : node.innerText).replaceAll(EOL_PATTERN, "");
}
editorDivPaste(event) {
const clipboardData = event.clipboardData || window.clipboardData;
const {
types
} = clipboardData;
if (types.length === 1 && types[0] === "text/plain") {
return;
}
event.preventDefault();
const paste = FreeTextEditor.#deserializeContent(clipboardData.getData("text") || "").replaceAll(EOL_PATTERN, "\n");
if (!paste) {
return;
}
const selection = window.getSelection();
if (!selection.rangeCount) {
return;
}
this.editorDiv.normalize();
selection.deleteFromDocument();
const range = selection.getRangeAt(0);
if (!paste.includes("\n")) {
range.insertNode(document.createTextNode(paste));
this.editorDiv.normalize();
selection.collapseToStart();
return;
}
const {
startContainer,
startOffset
} = range;
const bufferBefore = [];
const bufferAfter = [];
if (startContainer.nodeType === Node.TEXT_NODE) {
const parent = startContainer.parentElement;
bufferAfter.push(startContainer.nodeValue.slice(startOffset).replaceAll(EOL_PATTERN, ""));
if (parent !== this.editorDiv) {
let buffer = bufferBefore;
for (const child of this.editorDiv.childNodes) {
if (child === parent) {
buffer = bufferAfter;
continue;
}
buffer.push(FreeTextEditor.#getNodeContent(child));
}
}
bufferBefore.push(startContainer.nodeValue.slice(0, startOffset).replaceAll(EOL_PATTERN, ""));
} else if (startContainer === this.editorDiv) {
let buffer = bufferBefore;
let i = 0;
for (const child of this.editorDiv.childNodes) {
if (i++ === startOffset) {
buffer = bufferAfter;
}
buffer.push(FreeTextEditor.#getNodeContent(child));
}
}
this.#content = `${bufferBefore.join("\n")}${paste}${bufferAfter.join("\n")}`;
this.#setContent();
const newRange = new Range();
let beforeLength = bufferBefore.reduce((acc, line) => acc + line.length, 0);
for (const {
firstChild
} of this.editorDiv.childNodes) {
if (firstChild.nodeType === Node.TEXT_NODE) {
const length = firstChild.nodeValue.length;
if (beforeLength <= length) {
newRange.setStart(firstChild, beforeLength);
newRange.setEnd(firstChild, beforeLength);
break;
}
beforeLength -= length;
}
}
selection.removeAllRanges();
selection.addRange(newRange);
}
#setContent() {
this.editorDiv.replaceChildren();
if (!this.#content) {
Expand Down Expand Up @@ -9232,11 +9310,11 @@ class HighlightEditor extends editor_editor.AnnotationEditor {
this.div.focus();
}
remove() {
super.remove();
this.#cleanDrawLayer();
this._reportTelemetry({
action: "deleted"
});
super.remove();
}
rebuild() {
if (!this.parent) {
Expand Down Expand Up @@ -9412,11 +9490,17 @@ class HighlightEditor extends editor_editor.AnnotationEditor {
}
select() {
super.select();
if (!this.#outlineId) {
return;
}
this.parent?.drawLayer.removeClass(this.#outlineId, "hovered");
this.parent?.drawLayer.addClass(this.#outlineId, "selected");
}
unselect() {
super.unselect();
if (!this.#outlineId) {
return;
}
this.parent?.drawLayer.removeClass(this.#outlineId, "selected");
if (!this.#isFreeHighlight) {
this.#setCaret(false);
Expand All @@ -9425,7 +9509,7 @@ class HighlightEditor extends editor_editor.AnnotationEditor {
get _mustFixPosition() {
return !this.#isFreeHighlight;
}
show(visible) {
show(visible = this._isVisible) {
super.show(visible);
if (this.parent) {
this.parent.drawLayer.show(this.#id, visible);
Expand Down Expand Up @@ -9880,7 +9964,7 @@ class InkEditor extends editor_editor.AnnotationEditor {
this.allRawPaths.push(currentPath);
this.paths.push(bezier);
this.bezierPath2D.push(path2D);
this.rebuild();
this._uiManager.rebuild(this);
};
const undo = () => {
this.allRawPaths.pop();
Expand Down Expand Up @@ -10504,7 +10588,7 @@ class StampEditor extends editor_editor.AnnotationEditor {
if (this.div === null) {
return;
}
if (this.#bitmapId) {
if (this.#bitmapId && this.#canvas === null) {
this.#getBitmap();
}
if (!this.isAttachedToDOM) {
Expand All @@ -10516,7 +10600,7 @@ class StampEditor extends editor_editor.AnnotationEditor {
this.div.focus();
}
isEmpty() {
return !(this.#bitmapPromise || this.#bitmap || this.#bitmapUrl || this.#bitmapFile);
return !(this.#bitmapPromise || this.#bitmap || this.#bitmapUrl || this.#bitmapFile || this.#bitmapId);
}
get isResizable() {
return true;
Expand Down Expand Up @@ -11130,6 +11214,7 @@ class AnnotationEditorLayer {
if (editor.needsToBeRebuilt()) {
editor.parent ||= this;
editor.rebuild();
editor.show();
} else {
this.add(editor);
}
Expand Down Expand Up @@ -11320,6 +11405,7 @@ class AnnotationEditorLayer {
(0,display_utils.setLayerDimensions)(this.div, viewport);
for (const editor of this.#uiManager.getEditors(this.pageIndex)) {
this.add(editor);
editor.rebuild();
}
this.updateMode();
}
Expand Down Expand Up @@ -12525,7 +12611,6 @@ class AnnotationEditor {
rebuild() {
this.div?.addEventListener("focusin", this.#boundFocusin);
this.div?.addEventListener("focusout", this.#boundFocusout);
this.show(this._isVisible);
}
rotate(_angle) {}
serialize(isForCopying = false, context = null) {
Expand Down Expand Up @@ -12569,6 +12654,7 @@ class AnnotationEditor {
}
this.#telemetryTimeouts = null;
}
this.parent = null;
}
get isResizable() {
return false;
Expand Down Expand Up @@ -12788,7 +12874,7 @@ class AnnotationEditor {
}
});
}
show(visible) {
show(visible = this._isVisible) {
this.div.classList.toggle("hidden", !visible);
this._isVisible = visible;
}
Expand Down Expand Up @@ -14745,6 +14831,7 @@ class AnnotationEditorUIManager {
layer.addOrRebuild(editor);
} else {
this.addEditor(editor);
this.addToAnnotationStorage(editor);
}
}
setActiveEditor(editor) {
Expand Down Expand Up @@ -16688,14 +16775,14 @@ __webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
/* harmony import */ var _shared_util_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(292);


let fs, canvas, path2d_polyfill;
let fs, canvas, path2d;
if (_shared_util_js__WEBPACK_IMPORTED_MODULE_1__.isNodeJS) {
fs = await import( /*webpackIgnore: true*/"fs");
try {
canvas = await import( /*webpackIgnore: true*/"canvas");
} catch {}
try {
path2d_polyfill = await import( /*webpackIgnore: true*/"path2d-polyfill");
path2d = await import( /*webpackIgnore: true*/"path2d");
} catch {}
}
const fetchData = function (url) {
Expand Down Expand Up @@ -18016,7 +18103,7 @@ _display_api_js__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.t


const pdfjsVersion = "4.1.0";
const pdfjsBuild = "14307c0";
const pdfjsBuild = "3d2eb36";

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });
Expand Down
2 changes: 1 addition & 1 deletion build/pdf.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/pdf.sandbox.mjs

Large diffs are not rendered by default.

Loading

0 comments on commit 0797090

Please sign in to comment.