[api-minor] Add a basic AbortSignal.any polyfill in PDF.js legacy builds
This is an admittedly very basic polyfill, to allow us to remove a bunch of inline feature testing, that I've thrown together based on reading https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static and related MDN articles. Compared to PR 19218 it's obviously much more "primitive", however the implementation is simple and it doesn't suffer from any licensing issues (since I wrote the code myself).
This commit is contained in:
parent
00e3a4d87a
commit
028e4f7ea8
@ -1172,6 +1172,37 @@ if (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev !== "undefined" &&
|
||||||
|
!PDFJSDev.test("SKIP_BABEL") &&
|
||||||
|
typeof AbortSignal.any !== "function"
|
||||||
|
) {
|
||||||
|
AbortSignal.any = function (iterable) {
|
||||||
|
const ac = new AbortController();
|
||||||
|
const { signal } = ac;
|
||||||
|
|
||||||
|
// Return immediately if any of the signals are already aborted.
|
||||||
|
for (const s of iterable) {
|
||||||
|
if (s.aborted) {
|
||||||
|
ac.abort(s.reason);
|
||||||
|
return signal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Register "abort" listeners for all signals.
|
||||||
|
for (const s of iterable) {
|
||||||
|
s.addEventListener(
|
||||||
|
"abort",
|
||||||
|
() => {
|
||||||
|
ac.abort(s.reason);
|
||||||
|
},
|
||||||
|
{ signal } // Automatically remove the listener.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return signal;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
_isValidExplicitDest,
|
_isValidExplicitDest,
|
||||||
AbortException,
|
AbortException,
|
||||||
|
|||||||
27
web/app.js
27
web/app.js
@ -559,11 +559,7 @@ const PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (appConfig.annotationEditorParams) {
|
if (appConfig.annotationEditorParams) {
|
||||||
if (
|
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
|
||||||
((typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
|
||||||
typeof AbortSignal.any === "function") &&
|
|
||||||
annotationEditorMode !== AnnotationEditorType.DISABLE
|
|
||||||
) {
|
|
||||||
const editorSignatureButton = appConfig.toolbar?.editorSignatureButton;
|
const editorSignatureButton = appConfig.toolbar?.editorSignatureButton;
|
||||||
if (editorSignatureButton && AppOptions.get("enableSignatureEditor")) {
|
if (editorSignatureButton && AppOptions.get("enableSignatureEditor")) {
|
||||||
editorSignatureButton.parentElement.hidden = false;
|
editorSignatureButton.parentElement.hidden = false;
|
||||||
@ -2075,19 +2071,14 @@ const PDFViewerApplication = {
|
|||||||
_windowAbortController: { signal },
|
_windowAbortController: { signal },
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
if (
|
this._touchManager = new TouchManager({
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
container: window,
|
||||||
typeof AbortSignal.any === "function"
|
isPinchingDisabled: () => pdfViewer.isInPresentationMode,
|
||||||
) {
|
isPinchingStopped: () => this.overlayManager?.active,
|
||||||
this._touchManager = new TouchManager({
|
onPinching: this.touchPinchCallback.bind(this),
|
||||||
container: window,
|
onPinchEnd: this.touchPinchEndCallback.bind(this),
|
||||||
isPinchingDisabled: () => pdfViewer.isInPresentationMode,
|
signal,
|
||||||
isPinchingStopped: () => this.overlayManager?.active,
|
});
|
||||||
onPinching: this.touchPinchCallback.bind(this),
|
|
||||||
onPinchEnd: this.touchPinchEndCallback.bind(this),
|
|
||||||
signal,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function addWindowResolutionChange(evt = null) {
|
function addWindowResolutionChange(evt = null) {
|
||||||
if (evt) {
|
if (evt) {
|
||||||
|
|||||||
@ -711,13 +711,7 @@ class PDFViewer {
|
|||||||
hiddenCapability.resolve();
|
hiddenCapability.resolve();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{ signal: AbortSignal.any([signal, ac.signal]) }
|
||||||
signal:
|
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
|
||||||
typeof AbortSignal.any === "function"
|
|
||||||
? AbortSignal.any([signal, ac.signal])
|
|
||||||
: signal,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
@ -914,11 +908,7 @@ class PDFViewer {
|
|||||||
viewer.before(element);
|
viewer.before(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
|
||||||
((typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
|
||||||
typeof AbortSignal.any === "function") &&
|
|
||||||
annotationEditorMode !== AnnotationEditorType.DISABLE
|
|
||||||
) {
|
|
||||||
const mode = annotationEditorMode;
|
const mode = annotationEditorMode;
|
||||||
|
|
||||||
if (pdfDocument.isPureXfa) {
|
if (pdfDocument.isPureXfa) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user