mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-03 04:47:21 +02:00
Compare commits
No commits in common. "60574fb7e30748140bcec4137043a3e8ebf22887" and "f72f240699a84b348895a0f1d44c6a0b706e3915" have entirely different histories.
60574fb7e3
...
f72f240699
@ -462,14 +462,32 @@ function getDocument(src = {}) {
|
|||||||
if (!url) {
|
if (!url) {
|
||||||
throw new Error("getDocument - no `url` parameter provided.");
|
throw new Error("getDocument - no `url` parameter provided.");
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-nested-ternary
|
let NetworkStream;
|
||||||
const NetworkStream = isValidFetchUrl(url)
|
|
||||||
? PDFFetchStream
|
if (
|
||||||
: 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,
|
||||||
@ -704,16 +722,6 @@ 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
|
||||||
@ -730,34 +738,40 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -765,7 +779,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -775,8 +789,8 @@ class PDFDataRangeTransport {
|
|||||||
* @param {number|undefined} total
|
* @param {number|undefined} total
|
||||||
*/
|
*/
|
||||||
onDataProgress(loaded, total) {
|
onDataProgress(loaded, total) {
|
||||||
this.#capability.promise.then(() => {
|
this._readyCapability.promise.then(() => {
|
||||||
for (const listener of this.#progressListeners) {
|
for (const listener of this._progressListeners) {
|
||||||
listener(loaded, total);
|
listener(loaded, total);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -786,23 +800,23 @@ class PDFDataRangeTransport {
|
|||||||
* @param {Uint8Array|null} chunk
|
* @param {Uint8Array|null} chunk
|
||||||
*/
|
*/
|
||||||
onDataProgressiveRead(chunk) {
|
onDataProgressiveRead(chunk) {
|
||||||
this.#capability.promise.then(() => {
|
this._readyCapability.promise.then(() => {
|
||||||
for (const listener of this.#progressiveReadListeners) {
|
for (const listener of this._progressiveReadListeners) {
|
||||||
listener(chunk);
|
listener(chunk);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onDataProgressiveDone() {
|
onDataProgressiveDone() {
|
||||||
this.#capability.promise.then(() => {
|
this._readyCapability.promise.then(() => {
|
||||||
for (const listener of this.#progressiveDoneListeners) {
|
for (const listener of this._progressiveDoneListeners) {
|
||||||
listener();
|
listener();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
transportReady() {
|
transportReady() {
|
||||||
this.#capability.resolve();
|
this._readyCapability.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -669,7 +669,7 @@ describe("FreeText Editor", () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
await page.evaluate(() => {
|
page.evaluate(() => {
|
||||||
window.PDFViewerApplication.eventBus.dispatch(
|
window.PDFViewerApplication.eventBus.dispatch(
|
||||||
"switchannotationeditorparams",
|
"switchannotationeditorparams",
|
||||||
{
|
{
|
||||||
@ -1290,7 +1290,7 @@ describe("FreeText Editor", () => {
|
|||||||
".selectedEditor .internal"
|
".selectedEditor .internal"
|
||||||
);
|
);
|
||||||
|
|
||||||
await page.evaluate(() => {
|
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;
|
||||||
await page.evaluate(val => {
|
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);
|
||||||
|
|
||||||
await page.evaluate(val => {
|
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);
|
||||||
|
|
||||||
await page.mouse.click(rect.x - 10, rect.y + 10);
|
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";
|
||||||
await page.evaluate(value => {
|
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";
|
||||||
await page.evaluate(value => {
|
page.evaluate(value => {
|
||||||
window.PDFViewerApplication.eventBus.dispatch(
|
window.PDFViewerApplication.eventBus.dispatch(
|
||||||
"switchannotationeditorparams",
|
"switchannotationeditorparams",
|
||||||
{
|
{
|
||||||
|
|||||||
@ -631,7 +631,6 @@ 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();
|
||||||
@ -1593,8 +1592,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 () => {
|
||||||
// Run sequentially to avoid clipboard issues.
|
await Promise.all(
|
||||||
for (const [, page] of pages) {
|
pages.map(async ([browserName, page]) => {
|
||||||
await switchToStamp(page);
|
await switchToStamp(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -1614,12 +1613,13 @@ 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 () => {
|
||||||
// Run sequentially to avoid clipboard issues.
|
await Promise.all(
|
||||||
for (const [, page] of pages) {
|
pages.map(async ([browserName, page]) => {
|
||||||
await switchToStamp(page);
|
await switchToStamp(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -1638,14 +1638,18 @@ 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(el => el.textContent, message);
|
const messageText = await page.evaluate(
|
||||||
|
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 () => {
|
||||||
// Run sequentially to avoid clipboard issues.
|
await Promise.all(
|
||||||
for (const [, page] of pages) {
|
pages.map(async ([browserName, page]) => {
|
||||||
await switchToStamp(page);
|
await switchToStamp(page);
|
||||||
|
|
||||||
const editorSelector = getEditorSelector(0);
|
const editorSelector = getEditorSelector(0);
|
||||||
@ -1666,7 +1670,8 @@ 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