Skip to content

Commit

Permalink
Merge pull request #19394 from calixteman/mv_supported_img_types
Browse files Browse the repository at this point in the history
Move the array containing the supported image mime types in display_utils
  • Loading branch information
calixteman authored Jan 30, 2025
2 parents 31deee2 + 2c737bc commit ec7270c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
15 changes: 15 additions & 0 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,20 @@ class OutputScale {
}
}

// See https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
// to know which types are supported by the browser.
const SupportedImageMimeTypes = [
"image/apng",
"image/avif",
"image/bmp",
"image/gif",
"image/jpeg",
"image/png",
"image/svg+xml",
"image/webp",
"image/x-icon",
];

export {
deprecated,
fetchData,
Expand All @@ -672,5 +686,6 @@ export {
setLayerDimensions,
StatTimer,
stopEvent,
SupportedImageMimeTypes,
SVG_NS,
};
4 changes: 2 additions & 2 deletions src/display/editor/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AnnotationEditorType, shadow } from "../../shared/util.js";
import { DrawingEditor, DrawingOptions } from "./draw.js";
import { AnnotationEditor } from "./editor.js";
import { SignatureExtractor } from "./drawers/signaturedraw.js";
import { StampEditor } from "./stamp.js";
import { SupportedImageMimeTypes } from "../display_utils.js";

class SignatureOptions extends DrawingOptions {
#viewParameters;
Expand Down Expand Up @@ -106,7 +106,7 @@ class SignatureEditor extends DrawingEditor {
async #extractSignature() {
const input = document.createElement("input");
input.type = "file";
input.accept = StampEditor.supportedTypesStr;
input.accept = SupportedImageMimeTypes.join(",");
const signal = this._uiManager._signal;
const { promise, resolve } = Promise.withResolvers();

Expand Down
39 changes: 7 additions & 32 deletions src/display/editor/stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* limitations under the License.
*/

import { AnnotationEditorType, AnnotationPrefix } from "../../shared/util.js";
import {
AnnotationEditorType,
AnnotationPrefix,
shadow,
} from "../../shared/util.js";
import { OutputScale, PixelsPerInch } from "../display_utils.js";
OutputScale,
PixelsPerInch,
SupportedImageMimeTypes,
} from "../display_utils.js";
import { AnnotationEditor } from "./editor.js";
import { StampAnnotationElement } from "../annotation_layer.js";

Expand Down Expand Up @@ -63,34 +63,9 @@ class StampEditor extends AnnotationEditor {
AnnotationEditor.initialize(l10n, uiManager);
}

static get supportedTypes() {
// See https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
// to know which types are supported by the browser.
const types = [
"apng",
"avif",
"bmp",
"gif",
"jpeg",
"png",
"svg+xml",
"webp",
"x-icon",
];
return shadow(
this,
"supportedTypes",
types.map(type => `image/${type}`)
);
}

static get supportedTypesStr() {
return shadow(this, "supportedTypesStr", this.supportedTypes.join(","));
}

/** @inheritdoc */
static isHandlingMimeForPasting(mime) {
return this.supportedTypes.includes(mime);
return SupportedImageMimeTypes.includes(mime);
}

/** @inheritdoc */
Expand Down Expand Up @@ -258,7 +233,7 @@ class StampEditor extends AnnotationEditor {
document.body.append(input);
}
input.type = "file";
input.accept = StampEditor.supportedTypesStr;
input.accept = SupportedImageMimeTypes.join(",");
const signal = this._uiManager._signal;
this.#bitmapPromise = new Promise(resolve => {
input.addEventListener(
Expand Down
2 changes: 2 additions & 0 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
RenderingCancelledException,
setLayerDimensions,
stopEvent,
SupportedImageMimeTypes,
} from "./display/display_utils.js";
import { AnnotationEditorLayer } from "./display/editor/annotation_editor_layer.js";
import { AnnotationEditorUIManager } from "./display/editor/tools.js";
Expand Down Expand Up @@ -126,6 +127,7 @@ export {
setLayerDimensions,
shadow,
stopEvent,
SupportedImageMimeTypes,
TextLayer,
TouchManager,
Util,
Expand Down
2 changes: 2 additions & 0 deletions test/unit/pdf_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
RenderingCancelledException,
setLayerDimensions,
stopEvent,
SupportedImageMimeTypes,
} from "../../src/display/display_utils.js";
import { AnnotationEditorLayer } from "../../src/display/editor/annotation_editor_layer.js";
import { AnnotationEditorUIManager } from "../../src/display/editor/tools.js";
Expand Down Expand Up @@ -103,6 +104,7 @@ const expectedAPI = Object.freeze({
setLayerDimensions,
shadow,
stopEvent,
SupportedImageMimeTypes,
TextLayer,
TouchManager,
Util,
Expand Down
2 changes: 2 additions & 0 deletions web/pdfjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const {
setLayerDimensions,
shadow,
stopEvent,
SupportedImageMimeTypes,
TextLayer,
TouchManager,
Util,
Expand Down Expand Up @@ -99,6 +100,7 @@ export {
setLayerDimensions,
shadow,
stopEvent,
SupportedImageMimeTypes,
TextLayer,
TouchManager,
Util,
Expand Down

0 comments on commit ec7270c

Please sign in to comment.