Stop duplicating the platform getter in multiple files

Currently both of the `AnnotationElement` and `KeyboardManager` classes contain *identical* `platform` getters, which seems like unnecessary duplication.
With the pre-processor we can also limit the feature-testing to only GENERIC builds, since `navigator` should always be available in browsers.
This commit is contained in:
Jonas Jenwald 2022-11-29 12:14:40 +01:00
parent 5d79cc5bee
commit 82d127883d
5 changed files with 24 additions and 27 deletions

View file

@ -738,6 +738,19 @@ class FeatureTest {
typeof OffscreenCanvas !== "undefined"
);
}
static get platform() {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
typeof navigator === "undefined"
) {
return shadow(this, "platform", { isWin: false, isMac: false });
}
return shadow(this, "platform", {
isWin: navigator.platform.includes("Win"),
isMac: navigator.platform.includes("Mac"),
});
}
}
const hexNumbers = [...Array(256).keys()].map(n =>