Compare commits
2 Commits
0b975558d0
...
v0.3.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 6386326473 | |||
| 54d4dc9545 |
@@ -1,11 +1,6 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import type { PdfFile } from '../pdf/pdfTypes';
|
import type { PdfFile } from '../pdf/pdfTypes';
|
||||||
import * as pdfjsLib from 'pdfjs-dist';
|
import { pdfjsLib } from '../pdf/pdfJs';
|
||||||
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker?worker&url';
|
|
||||||
|
|
||||||
// pdf.js worker setup
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
(pdfjsLib as any).GlobalWorkerOptions.workerSrc = pdfjsWorker;
|
|
||||||
|
|
||||||
interface PagePreviewModalProps {
|
interface PagePreviewModalProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
|||||||
9
src/pdf/pdfJs.ts
Normal file
9
src/pdf/pdfJs.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import './uint8ArrayToHexPolyfill';
|
||||||
|
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.mjs';
|
||||||
|
import pdfjsWorker from './pdfjsWorker?worker&url';
|
||||||
|
|
||||||
|
// pdf.js worker setup for Vite.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
(pdfjsLib as any).GlobalWorkerOptions.workerSrc = pdfjsWorker;
|
||||||
|
|
||||||
|
export { pdfjsLib };
|
||||||
@@ -1,9 +1,4 @@
|
|||||||
import * as pdfjsLib from 'pdfjs-dist';
|
import { pdfjsLib } from './pdfJs';
|
||||||
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker?worker&url';
|
|
||||||
|
|
||||||
// pdf.js worker setup for Vite
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
(pdfjsLib as any).GlobalWorkerOptions.workerSrc = pdfjsWorker;
|
|
||||||
|
|
||||||
type RotationsMap = Record<number, number>; // key: 0-based page index, value: degrees
|
type RotationsMap = Record<number, number>; // key: 0-based page index, value: degrees
|
||||||
|
|
||||||
|
|||||||
2
src/pdf/pdfjsWorker.ts
Normal file
2
src/pdf/pdfjsWorker.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import './uint8ArrayToHexPolyfill';
|
||||||
|
import 'pdfjs-dist/legacy/build/pdf.worker.mjs';
|
||||||
22
src/pdf/uint8ArrayToHexPolyfill.ts
Normal file
22
src/pdf/uint8ArrayToHexPolyfill.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
type Uint8ArrayWithToHex = Uint8Array & {
|
||||||
|
toHex?: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8ArrayPrototype = Uint8Array.prototype as Uint8ArrayWithToHex;
|
||||||
|
|
||||||
|
if (typeof uint8ArrayPrototype.toHex !== 'function') {
|
||||||
|
Object.defineProperty(Uint8Array.prototype, 'toHex', {
|
||||||
|
value: function toHex(this: Uint8Array): string {
|
||||||
|
const hex = new Array<string>(this.length);
|
||||||
|
|
||||||
|
for (let index = 0; index < this.length; index += 1) {
|
||||||
|
const value = this[index].toString(16);
|
||||||
|
hex[index] = value.length === 1 ? `0${value}` : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hex.join('');
|
||||||
|
},
|
||||||
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user