Skip to content

Commit 05efe30

Browse files
committed
Change PixelsPerInch to a class with static properties (issue 14579)
*Please note:* I'm completely fine with this patch being rejected, and the issue instead closed as WONTFIX, since this is unfortunately a case where the TypeScript definitions dictate how we can/cannot write JavaScript code. Apparently the TypeScript definitions generation converts the existing `PixelsPerInch` code into a `namespace` and simply ignores the getter; please see https://github.com/mozilla/pdfjs-dist/blob/a7fc0d33a11d032741f44d0b623780253747da10/types/src/display/display_utils.d.ts#L223-L226 Initially I tried tagging `PixelsPerInch` as en `@enum`, see https://jsdoc.app/tags-enum.html, however that unfortunately didn't help. Hence the only good/simple solution, as far as I'm concerned, is to convert `PixelsPerInch` into a class with `static` properties. This patch results in the following diff, for the `gulp types` build target: ```diff @@ -195,9 +195,10 @@ */ static toDateObject(input: string): Date | null; } -export namespace PixelsPerInch { - const CSS: number; - const PDF: number; +export class PixelsPerInch { + static CSS: number; + static PDF: number; + static PDF_TO_CSS_UNITS: number; } declare const RenderingCancelledException_base: any; export class RenderingCancelledException extends RenderingCancelledException_base { ```
1 parent 530af48 commit 05efe30

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/display/display_utils.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,20 @@ import {
2222
import {
2323
BaseException,
2424
isString,
25-
shadow,
2625
stringToBytes,
2726
Util,
2827
warn,
2928
} from "../shared/util.js";
3029

3130
const SVG_NS = "http://www.w3.org/2000/svg";
3231

33-
const PixelsPerInch = {
34-
CSS: 96.0,
35-
PDF: 72.0,
32+
class PixelsPerInch {
33+
static CSS = 96.0;
3634

37-
/** @type {number} */
38-
get PDF_TO_CSS_UNITS() {
39-
return shadow(this, "PDF_TO_CSS_UNITS", this.CSS / this.PDF);
40-
},
41-
};
35+
static PDF = 72.0;
36+
37+
static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
38+
}
4239

4340
class DOMCanvasFactory extends BaseCanvasFactory {
4441
constructor({ ownerDocument = globalThis.document } = {}) {

0 commit comments

Comments
 (0)