Skip to content

Commit

Permalink
Update pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jun 9, 2024
1 parent 83ca394 commit 6625efc
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 127 deletions.
40 changes: 38 additions & 2 deletions build/pdf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,8 @@ class AnnotationEditorUIManager {
#boundFocus = this.focus.bind(this);
#boundCopy = this.copy.bind(this);
#boundCut = this.cut.bind(this);
#boundDragOver = this.dragOver.bind(this);
#boundDrop = this.drop.bind(this);
#boundPaste = this.paste.bind(this);
#boundKeydown = this.keydown.bind(this);
#boundKeyup = this.keyup.bind(this);
Expand Down Expand Up @@ -2313,6 +2315,7 @@ class AnnotationEditorUIManager {
this._eventBus._on("scalechanging", this.#boundOnScaleChanging);
this._eventBus._on("rotationchanging", this.#boundOnRotationChanging);
this.#addSelectionListener();
this.#addDragAndDropListeners();
this.#addKeyboardManager();
this.#annotationStorage = pdfDocument.annotationStorage;
this.#filterFactory = pdfDocument.filterFactory;
Expand All @@ -2327,6 +2330,7 @@ class AnnotationEditorUIManager {
this.isShiftKeyDown = false;
}
destroy() {
this.#removeDragAndDropListeners();
this.#removeKeyboardManager();
this.#removeFocusManager();
this._eventBus._off("editingaction", this.#boundOnEditingAction);
Expand Down Expand Up @@ -2622,6 +2626,14 @@ class AnnotationEditorUIManager {
document.removeEventListener("cut", this.#boundCut);
document.removeEventListener("paste", this.#boundPaste);
}
#addDragAndDropListeners() {
document.addEventListener("dragover", this.#boundDragOver);
document.addEventListener("drop", this.#boundDrop);
}
#removeDragAndDropListeners() {
document.removeEventListener("dragover", this.#boundDragOver);
document.removeEventListener("drop", this.#boundDrop);
}
addEditListeners() {
this.#addKeyboardManager();
this.#addCopyPasteListeners();
Expand All @@ -2630,6 +2642,30 @@ class AnnotationEditorUIManager {
this.#removeKeyboardManager();
this.#removeCopyPasteListeners();
}
dragOver(event) {
for (const {
type
} of event.dataTransfer.items) {
for (const editorType of this.#editorTypes) {
if (editorType.isHandlingMimeForPasting(type)) {
event.dataTransfer.dropEffect = "copy";
event.preventDefault();
return;
}
}
}
}
drop(event) {
for (const item of event.dataTransfer.items) {
for (const editorType of this.#editorTypes) {
if (editorType.isHandlingMimeForPasting(item.type)) {
editorType.paste(item, this.currentLayer);
event.preventDefault();
return;
}
}
}
}
copy(event) {
event.preventDefault();
this.#activeEditor?.commitOrRemove();
Expand Down Expand Up @@ -12492,7 +12528,7 @@ class InternalRenderTask {
}
}
const version = "4.4.0";
const build = "53dfb5a";
const build = "bb73d2a";

;// CONCATENATED MODULE: ./src/shared/scripting_utils.js
function makeColorComp(n) {
Expand Down Expand Up @@ -19377,7 +19413,7 @@ class DrawLayer {


const pdfjsVersion = "4.4.0";
const pdfjsBuild = "53dfb5a";
const pdfjsBuild = "bb73d2a";

var __webpack_exports__AbortException = __webpack_exports__.AbortException;
var __webpack_exports__AnnotationEditorLayer = __webpack_exports__.AnnotationEditorLayer;
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.

317 changes: 224 additions & 93 deletions build/pdf.worker.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/pdf.worker.mjs.map

Large diffs are not rendered by default.

51 changes: 24 additions & 27 deletions web/viewer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3669,8 +3669,10 @@ class DownloadManager {
this.downloadData(data, filename, contentType);
return false;
}
download(blob, url, filename, _options) {
const blobUrl = URL.createObjectURL(blob);
download(data, url, filename, _options) {
const blobUrl = URL.createObjectURL(new Blob([data], {
type: "application/pdf"
}));
download(blobUrl, filename);
}
}
Expand Down Expand Up @@ -8936,13 +8938,6 @@ class TextLayerBuilder {
this.div.tabIndex = 0;
this.div.className = "textLayer";
}
#finishRendering() {
this.#renderingDone = true;
const endOfContent = document.createElement("div");
endOfContent.className = "endOfContent";
this.div.append(endOfContent);
this.#bindMouse(endOfContent);
}
async render(viewport, textContentParams = null) {
if (this.#renderingDone && this.#textLayer) {
this.#textLayer.update({
Expand All @@ -8968,7 +8963,11 @@ class TextLayerBuilder {
this.highlighter?.setTextMapping(textDivs, textContentItemsStr);
this.accessibilityManager?.setTextMapping(textDivs);
await this.#textLayer.render();
this.#finishRendering();
this.#renderingDone = true;
const endOfContent = document.createElement("div");
endOfContent.className = "endOfContent";
this.div.append(endOfContent);
this.#bindMouse(endOfContent);
this.#onAppend?.(this.div);
this.highlighter?.enable();
this.accessibilityManager?.enable();
Expand Down Expand Up @@ -12409,17 +12408,21 @@ const PDFViewerApplication = {
});
});
appConfig.mainContainer.addEventListener("dragover", function (evt) {
evt.preventDefault();
evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
for (const item of evt.dataTransfer.items) {
if (item.type === "application/pdf") {
evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
evt.preventDefault();
evt.stopPropagation();
return;
}
}
});
appConfig.mainContainer.addEventListener("drop", function (evt) {
evt.preventDefault();
const {
files
} = evt.dataTransfer;
if (!files || files.length === 0) {
if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
return;
}
evt.preventDefault();
evt.stopPropagation();
eventBus.dispatch("fileinputchange", {
source: this,
fileInput: evt.dataTransfer
Expand Down Expand Up @@ -12671,12 +12674,9 @@ const PDFViewerApplication = {
try {
this._ensureDownloadComplete();
const data = await this.pdfDocument.getData();
const blob = new Blob([data], {
type: "application/pdf"
});
await this.downloadManager.download(blob, url, filename, options);
this.downloadManager.download(data, url, filename, options);
} catch {
await this.downloadManager.downloadUrl(url, filename, options);
this.downloadManager.downloadUrl(url, filename, options);
}
},
async save(options = {}) {
Expand All @@ -12690,10 +12690,7 @@ const PDFViewerApplication = {
try {
this._ensureDownloadComplete();
const data = await this.pdfDocument.saveDocument();
const blob = new Blob([data], {
type: "application/pdf"
});
await this.downloadManager.download(blob, url, filename, options);
this.downloadManager.download(data, url, filename, options);
} catch (reason) {
console.error(`Error when saving the document: ${reason.message}`);
await this.download(options);
Expand Down Expand Up @@ -14290,7 +14287,7 @@ function webViewerReportTelemetry({


const pdfjsVersion = "4.4.0";
const pdfjsBuild = "53dfb5a";
const pdfjsBuild = "bb73d2a";
const AppConstants = {
LinkTarget: LinkTarget,
RenderingStates: RenderingStates,
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.mjs.map

Large diffs are not rendered by default.

0 comments on commit 6625efc

Please sign in to comment.