Merge pull request #14551 from Snuffleupagus/mv-createObjectURL
[api-minor] Stop exposing the `createObjectURL` helper function in the API
This commit is contained in:
commit
e9fd67a3f6
@ -15,7 +15,6 @@
|
||||
/* globals __non_webpack_require__ */
|
||||
|
||||
import {
|
||||
createObjectURL,
|
||||
FONT_IDENTITY_MATRIX,
|
||||
IDENTITY_MATRIX,
|
||||
ImageKind,
|
||||
@ -50,6 +49,36 @@ if (
|
||||
const LINE_CAP_STYLES = ["butt", "round", "square"];
|
||||
const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
|
||||
|
||||
const createObjectURL = function (
|
||||
data,
|
||||
contentType = "",
|
||||
forceDataSchema = false
|
||||
) {
|
||||
if (
|
||||
URL.createObjectURL &&
|
||||
typeof Blob !== "undefined" &&
|
||||
!forceDataSchema
|
||||
) {
|
||||
return URL.createObjectURL(new Blob([data], { type: contentType }));
|
||||
}
|
||||
// Blob/createObjectURL is not available, falling back to data schema.
|
||||
const digits =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
let buffer = `data:${contentType};base64,`;
|
||||
for (let i = 0, ii = data.length; i < ii; i += 3) {
|
||||
const b1 = data[i] & 0xff;
|
||||
const b2 = data[i + 1] & 0xff;
|
||||
const b3 = data[i + 2] & 0xff;
|
||||
const d1 = b1 >> 2,
|
||||
d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
||||
const d3 = i + 1 < ii ? ((b2 & 0xf) << 2) | (b3 >> 6) : 64;
|
||||
const d4 = i + 2 < ii ? b3 & 0x3f : 64;
|
||||
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
|
||||
const convertImgDataToPng = (function () {
|
||||
const PNG_HEADER = new Uint8Array([
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
||||
|
@ -23,7 +23,6 @@
|
||||
import {
|
||||
AnnotationMode,
|
||||
CMapCompressionType,
|
||||
createObjectURL,
|
||||
createPromiseCapability,
|
||||
createValidAbsoluteUrl,
|
||||
InvalidPDFException,
|
||||
@ -109,7 +108,6 @@ export {
|
||||
AnnotationMode,
|
||||
build,
|
||||
CMapCompressionType,
|
||||
createObjectURL,
|
||||
createPromiseCapability,
|
||||
createValidAbsoluteUrl,
|
||||
getDocument,
|
||||
|
@ -1109,28 +1109,6 @@ function createPromiseCapability() {
|
||||
return capability;
|
||||
}
|
||||
|
||||
function createObjectURL(data, contentType = "", forceDataSchema = false) {
|
||||
if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
|
||||
return URL.createObjectURL(new Blob([data], { type: contentType }));
|
||||
}
|
||||
// Blob/createObjectURL is not available, falling back to data schema.
|
||||
const digits =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
let buffer = `data:${contentType};base64,`;
|
||||
for (let i = 0, ii = data.length; i < ii; i += 3) {
|
||||
const b1 = data[i] & 0xff;
|
||||
const b2 = data[i + 1] & 0xff;
|
||||
const b3 = data[i + 2] & 0xff;
|
||||
const d1 = b1 >> 2,
|
||||
d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
||||
const d3 = i + 1 < ii ? ((b2 & 0xf) << 2) | (b3 >> 6) : 64;
|
||||
const d4 = i + 2 < ii ? b3 & 0x3f : 64;
|
||||
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
export {
|
||||
AbortException,
|
||||
AnnotationActionEventType,
|
||||
@ -1149,7 +1127,6 @@ export {
|
||||
BaseException,
|
||||
bytesToString,
|
||||
CMapCompressionType,
|
||||
createObjectURL,
|
||||
createPromiseCapability,
|
||||
createValidAbsoluteUrl,
|
||||
DocumentActionEventType,
|
||||
|
@ -21,7 +21,7 @@ import {
|
||||
isValidFetchUrl,
|
||||
PDFDateString,
|
||||
} from "../../src/display/display_utils.js";
|
||||
import { createObjectURL } from "../../src/shared/util.js";
|
||||
import { bytesToString } from "../../src/shared/util.js";
|
||||
import { isNodeJS } from "../../src/shared/is_node.js";
|
||||
|
||||
describe("display_utils", function () {
|
||||
@ -320,7 +320,9 @@ describe("display_utils", function () {
|
||||
pending("Blob in not supported in Node.js.");
|
||||
}
|
||||
const typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
||||
const blobUrl = createObjectURL(typedArray, "application/pdf");
|
||||
const blobUrl = URL.createObjectURL(
|
||||
new Blob([typedArray], { type: "application/pdf" })
|
||||
);
|
||||
// Sanity check to ensure that a "blob:" URL was returned.
|
||||
expect(blobUrl.startsWith("blob:")).toEqual(true);
|
||||
|
||||
@ -328,12 +330,9 @@ describe("display_utils", function () {
|
||||
});
|
||||
|
||||
it('gets fallback filename from query string appended to "data:" URL', function () {
|
||||
const typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
||||
const dataUrl = createObjectURL(
|
||||
typedArray,
|
||||
"application/pdf",
|
||||
/* forceDataSchema = */ true
|
||||
);
|
||||
const typedArray = new Uint8Array([1, 2, 3, 4, 5]),
|
||||
str = bytesToString(typedArray);
|
||||
const dataUrl = `data:application/pdf;base64,${btoa(str)}`;
|
||||
// Sanity check to ensure that a "data:" URL was returned.
|
||||
expect(dataUrl.startsWith("data:")).toEqual(true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user