[api-minor] Stop exposing the createObjectURL
helper function in the API
With recent changes, specifically PR 14515 *and* the previous patch, the `createObjectURL` helper function is now only used with the SVG back-end. All other call-sites, throughout the code-base, are now using `URL.createObjectURL(...)` directly and it no longer seems necessary to keep exposing the helper function in the API. Finally, the `createObjectURL` helper function is moved into the `src/display/svg.js` file to avoid unnecessarily duplicating this code on both the main- and worker-threads.
This commit is contained in:
parent
0daab88a48
commit
b87a243222
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user