mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-03 04:47:21 +02:00
Compare commits
8 Commits
f72f240699
...
60574fb7e3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60574fb7e3 | ||
|
|
393e799e49 | ||
|
|
819671d42f | ||
|
|
6355dd7ded | ||
|
|
f6e4b1cf4a | ||
|
|
30bba5f165 | ||
|
|
a882195e9b | ||
|
|
99b23ea1f6 |
@ -462,32 +462,14 @@ function getDocument(src = {}) {
|
|||||||
if (!url) {
|
if (!url) {
|
||||||
throw new Error("getDocument - no `url` parameter provided.");
|
throw new Error("getDocument - no `url` parameter provided.");
|
||||||
}
|
}
|
||||||
let NetworkStream;
|
// eslint-disable-next-line no-nested-ternary
|
||||||
|
const NetworkStream = isValidFetchUrl(url)
|
||||||
if (
|
? PDFFetchStream
|
||||||
typeof PDFJSDev !== "undefined" &&
|
: typeof PDFJSDev !== "undefined" &&
|
||||||
PDFJSDev.test("GENERIC") &&
|
PDFJSDev.test("GENERIC") &&
|
||||||
isNodeJS
|
isNodeJS
|
||||||
) {
|
? PDFNodeStream
|
||||||
if (isValidFetchUrl(url)) {
|
|
||||||
if (
|
|
||||||
typeof fetch === "undefined" ||
|
|
||||||
typeof Response === "undefined" ||
|
|
||||||
!("body" in Response.prototype)
|
|
||||||
) {
|
|
||||||
throw new Error(
|
|
||||||
"getDocument - the Fetch API was disabled in Node.js, see `--no-experimental-fetch`."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
NetworkStream = PDFFetchStream;
|
|
||||||
} else {
|
|
||||||
NetworkStream = PDFNodeStream;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
NetworkStream = isValidFetchUrl(url)
|
|
||||||
? PDFFetchStream
|
|
||||||
: PDFNetworkStream;
|
: PDFNetworkStream;
|
||||||
}
|
|
||||||
|
|
||||||
networkStream = new NetworkStream({
|
networkStream = new NetworkStream({
|
||||||
url,
|
url,
|
||||||
@ -722,6 +704,16 @@ class PDFDocumentLoadingTask {
|
|||||||
* main-thread memory usage, however it will take ownership of the TypedArrays.
|
* main-thread memory usage, however it will take ownership of the TypedArrays.
|
||||||
*/
|
*/
|
||||||
class PDFDataRangeTransport {
|
class PDFDataRangeTransport {
|
||||||
|
#capability = Promise.withResolvers();
|
||||||
|
|
||||||
|
#progressiveDoneListeners = [];
|
||||||
|
|
||||||
|
#progressiveReadListeners = [];
|
||||||
|
|
||||||
|
#progressListeners = [];
|
||||||
|
|
||||||
|
#rangeListeners = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} length
|
* @param {number} length
|
||||||
* @param {Uint8Array|null} initialData
|
* @param {Uint8Array|null} initialData
|
||||||
@ -738,40 +730,34 @@ class PDFDataRangeTransport {
|
|||||||
this.initialData = initialData;
|
this.initialData = initialData;
|
||||||
this.progressiveDone = progressiveDone;
|
this.progressiveDone = progressiveDone;
|
||||||
this.contentDispositionFilename = contentDispositionFilename;
|
this.contentDispositionFilename = contentDispositionFilename;
|
||||||
|
|
||||||
this._rangeListeners = [];
|
|
||||||
this._progressListeners = [];
|
|
||||||
this._progressiveReadListeners = [];
|
|
||||||
this._progressiveDoneListeners = [];
|
|
||||||
this._readyCapability = Promise.withResolvers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {function} listener
|
* @param {function} listener
|
||||||
*/
|
*/
|
||||||
addRangeListener(listener) {
|
addRangeListener(listener) {
|
||||||
this._rangeListeners.push(listener);
|
this.#rangeListeners.push(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {function} listener
|
* @param {function} listener
|
||||||
*/
|
*/
|
||||||
addProgressListener(listener) {
|
addProgressListener(listener) {
|
||||||
this._progressListeners.push(listener);
|
this.#progressListeners.push(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {function} listener
|
* @param {function} listener
|
||||||
*/
|
*/
|
||||||
addProgressiveReadListener(listener) {
|
addProgressiveReadListener(listener) {
|
||||||
this._progressiveReadListeners.push(listener);
|
this.#progressiveReadListeners.push(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {function} listener
|
* @param {function} listener
|
||||||
*/
|
*/
|
||||||
addProgressiveDoneListener(listener) {
|
addProgressiveDoneListener(listener) {
|
||||||
this._progressiveDoneListeners.push(listener);
|
this.#progressiveDoneListeners.push(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -779,7 +765,7 @@ class PDFDataRangeTransport {
|
|||||||
* @param {Uint8Array|null} chunk
|
* @param {Uint8Array|null} chunk
|
||||||
*/
|
*/
|
||||||
onDataRange(begin, chunk) {
|
onDataRange(begin, chunk) {
|
||||||
for (const listener of this._rangeListeners) {
|
for (const listener of this.#rangeListeners) {
|
||||||
listener(begin, chunk);
|
listener(begin, chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -789,8 +775,8 @@ class PDFDataRangeTransport {
|
|||||||
* @param {number|undefined} total
|
* @param {number|undefined} total
|
||||||
*/
|
*/
|
||||||
onDataProgress(loaded, total) {
|
onDataProgress(loaded, total) {
|
||||||
this._readyCapability.promise.then(() => {
|
this.#capability.promise.then(() => {
|
||||||
for (const listener of this._progressListeners) {
|
for (const listener of this.#progressListeners) {
|
||||||
listener(loaded, total);
|
listener(loaded, total);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -800,23 +786,23 @@ class PDFDataRangeTransport {
|
|||||||
* @param {Uint8Array|null} chunk
|
* @param {Uint8Array|null} chunk
|
||||||
*/
|
*/
|
||||||
onDataProgressiveRead(chunk) {
|
onDataProgressiveRead(chunk) {
|
||||||
this._readyCapability.promise.then(() => {
|
this.#capability.promise.then(() => {
|
||||||
for (const listener of this._progressiveReadListeners) {
|
for (const listener of this.#progressiveReadListeners) {
|
||||||
listener(chunk);
|
listener(chunk);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onDataProgressiveDone() {
|
onDataProgressiveDone() {
|
||||||
this._readyCapability.promise.then(() => {
|
this.#capability.promise.then(() => {
|
||||||
for (const listener of this._progressiveDoneListeners) {
|
for (const listener of this.#progressiveDoneListeners) {
|
||||||
listener();
|
listener();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
transportReady() {
|
transportReady() {
|
||||||
this._readyCapability.resolve();
|
this.#capability.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -669,7 +669,7 @@ describe("FreeText Editor", () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
window.PDFViewerApplication.eventBus.dispatch(
|
window.PDFViewerApplication.eventBus.dispatch(
|
||||||
"switchannotationeditorparams",
|
"switchannotationeditorparams",
|
||||||
{
|
{
|
||||||
@ -1290,7 +1290,7 @@ describe("FreeText Editor", () => {
|
|||||||
".selectedEditor .internal"
|
".selectedEditor .internal"
|
||||||
);
|
);
|
||||||
|
|
||||||
page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
window.PDFViewerApplication.eventBus.dispatch(
|
window.PDFViewerApplication.eventBus.dispatch(
|
||||||
"switchannotationeditorparams",
|
"switchannotationeditorparams",
|
||||||
{
|
{
|
||||||
|
|||||||
@ -626,7 +626,7 @@ describe("Highlight Editor", () => {
|
|||||||
const { width: prevWidth } = await getRect(page, editorSelector);
|
const { width: prevWidth } = await getRect(page, editorSelector);
|
||||||
|
|
||||||
value = 24;
|
value = 24;
|
||||||
page.evaluate(val => {
|
await page.evaluate(val => {
|
||||||
window.PDFViewerApplication.eventBus.dispatch(
|
window.PDFViewerApplication.eventBus.dispatch(
|
||||||
"switchannotationeditorparams",
|
"switchannotationeditorparams",
|
||||||
{
|
{
|
||||||
@ -763,7 +763,7 @@ describe("Highlight Editor", () => {
|
|||||||
|
|
||||||
const { width: prevWidth } = await getRect(page, editorSelector);
|
const { width: prevWidth } = await getRect(page, editorSelector);
|
||||||
|
|
||||||
page.evaluate(val => {
|
await page.evaluate(val => {
|
||||||
window.PDFViewerApplication.eventBus.dispatch(
|
window.PDFViewerApplication.eventBus.dispatch(
|
||||||
"switchannotationeditorparams",
|
"switchannotationeditorparams",
|
||||||
{
|
{
|
||||||
|
|||||||
@ -302,7 +302,7 @@ describe("Ink Editor", () => {
|
|||||||
await page.mouse.up();
|
await page.mouse.up();
|
||||||
await awaitPromise(clickHandle);
|
await awaitPromise(clickHandle);
|
||||||
|
|
||||||
page.mouse.click(rect.x - 10, rect.y + 10);
|
await page.mouse.click(rect.x - 10, rect.y + 10);
|
||||||
await page.waitForSelector(`${getEditorSelector(0)}.disabled`);
|
await page.waitForSelector(`${getEditorSelector(0)}.disabled`);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -583,7 +583,7 @@ describe("Ink Editor", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const red = "#ff0000";
|
const red = "#ff0000";
|
||||||
page.evaluate(value => {
|
await page.evaluate(value => {
|
||||||
window.PDFViewerApplication.eventBus.dispatch(
|
window.PDFViewerApplication.eventBus.dispatch(
|
||||||
"switchannotationeditorparams",
|
"switchannotationeditorparams",
|
||||||
{
|
{
|
||||||
@ -763,7 +763,7 @@ describe("Ink Editor", () => {
|
|||||||
await selectEditor(page, pdfjsA);
|
await selectEditor(page, pdfjsA);
|
||||||
|
|
||||||
const red = "#ff0000";
|
const red = "#ff0000";
|
||||||
page.evaluate(value => {
|
await page.evaluate(value => {
|
||||||
window.PDFViewerApplication.eventBus.dispatch(
|
window.PDFViewerApplication.eventBus.dispatch(
|
||||||
"switchannotationeditorparams",
|
"switchannotationeditorparams",
|
||||||
{
|
{
|
||||||
|
|||||||
@ -631,6 +631,7 @@ describe("Stamp Editor", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("must check that the alt-text button is here when pasting in the second tab", async () => {
|
it("must check that the alt-text button is here when pasting in the second tab", async () => {
|
||||||
|
// Run sequentially to avoid clipboard issues.
|
||||||
for (let i = 0; i < pages1.length; i++) {
|
for (let i = 0; i < pages1.length; i++) {
|
||||||
const [, page1] = pages1[i];
|
const [, page1] = pages1[i];
|
||||||
await page1.bringToFront();
|
await page1.bringToFront();
|
||||||
@ -1592,8 +1593,8 @@ describe("Stamp Editor", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("must check that deleting an image can be undone using the undo button", async () => {
|
it("must check that deleting an image can be undone using the undo button", async () => {
|
||||||
await Promise.all(
|
// Run sequentially to avoid clipboard issues.
|
||||||
pages.map(async ([browserName, page]) => {
|
for (const [, page] of pages) {
|
||||||
await switchToStamp(page);
|
await switchToStamp(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -1613,13 +1614,12 @@ describe("Stamp Editor", () => {
|
|||||||
await waitForSerialized(page, 1);
|
await waitForSerialized(page, 1);
|
||||||
await page.waitForSelector(editorSelector);
|
await page.waitForSelector(editorSelector);
|
||||||
await page.waitForSelector(`${editorSelector} canvas`);
|
await page.waitForSelector(`${editorSelector} canvas`);
|
||||||
})
|
}
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("must check that the undo deletion popup displays the correct message", async () => {
|
it("must check that the undo deletion popup displays the correct message", async () => {
|
||||||
await Promise.all(
|
// Run sequentially to avoid clipboard issues.
|
||||||
pages.map(async ([browserName, page]) => {
|
for (const [, page] of pages) {
|
||||||
await switchToStamp(page);
|
await switchToStamp(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -1638,18 +1638,14 @@ describe("Stamp Editor", () => {
|
|||||||
return messageElement && messageElement.textContent.trim() !== "";
|
return messageElement && messageElement.textContent.trim() !== "";
|
||||||
});
|
});
|
||||||
const message = await page.waitForSelector("#editorUndoBarMessage");
|
const message = await page.waitForSelector("#editorUndoBarMessage");
|
||||||
const messageText = await page.evaluate(
|
const messageText = await page.evaluate(el => el.textContent, message);
|
||||||
el => el.textContent,
|
|
||||||
message
|
|
||||||
);
|
|
||||||
expect(messageText).toContain("Image removed");
|
expect(messageText).toContain("Image removed");
|
||||||
})
|
}
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("must check that the popup disappears when a new image is inserted", async () => {
|
it("must check that the popup disappears when a new image is inserted", async () => {
|
||||||
await Promise.all(
|
// Run sequentially to avoid clipboard issues.
|
||||||
pages.map(async ([browserName, page]) => {
|
for (const [, page] of pages) {
|
||||||
await switchToStamp(page);
|
await switchToStamp(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -1670,8 +1666,7 @@ describe("Stamp Editor", () => {
|
|||||||
await waitForImage(page, getEditorSelector(1));
|
await waitForImage(page, getEditorSelector(1));
|
||||||
await waitForSerialized(page, 1);
|
await waitForSerialized(page, 1);
|
||||||
await page.waitForSelector("#editorUndoBar", { hidden: true });
|
await page.waitForSelector("#editorUndoBar", { hidden: true });
|
||||||
})
|
}
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user