mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
unvendor: Replace pdfjs-dist
This commit is contained in:
1
public/global.d.ts
vendored
1
public/global.d.ts
vendored
@@ -1,6 +1,5 @@
|
||||
// Global namespace modules
|
||||
declare var droll;
|
||||
declare var pdfjsLib;
|
||||
declare var Popper;
|
||||
declare var showdown;
|
||||
declare var showdownKatex;
|
||||
|
@@ -22,7 +22,6 @@
|
||||
"seedrandom",
|
||||
"showdown-katex",
|
||||
"droll",
|
||||
"pdfjs-dist",
|
||||
"@mozilla/readability"
|
||||
]
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import Handlebars from 'handlebars';
|
||||
import css from '@adobe/css-tools';
|
||||
import Bowser from 'bowser';
|
||||
import ePub from 'epubjs';
|
||||
import * as pdfjsLib from 'pdfjs-dist/webpack.mjs';
|
||||
|
||||
/**
|
||||
* Expose the libraries to the 'window' object.
|
||||
@@ -51,6 +52,7 @@ export default {
|
||||
css,
|
||||
Bowser,
|
||||
ePub,
|
||||
pdfjsLib,
|
||||
};
|
||||
|
||||
export {
|
||||
@@ -62,4 +64,5 @@ export {
|
||||
css,
|
||||
Bowser,
|
||||
ePub,
|
||||
pdfjsLib,
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { DOMPurify, ePub } from '../lib.js';
|
||||
import { DOMPurify, ePub, pdfjsLib } from '../lib.js';
|
||||
|
||||
import { getContext } from './extensions.js';
|
||||
import { characters, getRequestHeaders, this_chid } from '../script.js';
|
||||
@@ -1493,40 +1493,6 @@ export async function getReadableText(document, textSelector = 'body') {
|
||||
* @returns {Promise<string>} A promise that resolves to the parsed text.
|
||||
*/
|
||||
export async function extractTextFromPDF(blob) {
|
||||
async function initPdfJs() {
|
||||
const promises = [];
|
||||
|
||||
const workerPromise = new Promise((resolve, reject) => {
|
||||
const workerScript = document.createElement('script');
|
||||
workerScript.type = 'module';
|
||||
workerScript.async = true;
|
||||
workerScript.src = 'lib/pdf.worker.mjs';
|
||||
workerScript.onload = resolve;
|
||||
workerScript.onerror = reject;
|
||||
document.head.appendChild(workerScript);
|
||||
});
|
||||
|
||||
promises.push(workerPromise);
|
||||
|
||||
const pdfjsPromise = new Promise((resolve, reject) => {
|
||||
const pdfjsScript = document.createElement('script');
|
||||
pdfjsScript.type = 'module';
|
||||
pdfjsScript.async = true;
|
||||
pdfjsScript.src = 'lib/pdf.mjs';
|
||||
pdfjsScript.onload = resolve;
|
||||
pdfjsScript.onerror = reject;
|
||||
document.head.appendChild(pdfjsScript);
|
||||
});
|
||||
|
||||
promises.push(pdfjsPromise);
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
if (!('pdfjsLib' in window)) {
|
||||
await initPdfJs();
|
||||
}
|
||||
|
||||
const buffer = await getFileBuffer(blob);
|
||||
const pdf = await pdfjsLib.getDocument(buffer).promise;
|
||||
const pages = [];
|
||||
|
Reference in New Issue
Block a user