compatibility.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* globals __non_webpack_require__ */
  16. import { isNodeJS } from "./is_node.js";
  17. // Support: Node.js<16.0.0
  18. (function checkNodeBtoa() {
  19. if (globalThis.btoa || !isNodeJS) {
  20. return;
  21. }
  22. globalThis.btoa = function (chars) {
  23. // eslint-disable-next-line no-undef
  24. return Buffer.from(chars, "binary").toString("base64");
  25. };
  26. })();
  27. // Support: Node.js<16.0.0
  28. (function checkNodeAtob() {
  29. if (globalThis.atob || !isNodeJS) {
  30. return;
  31. }
  32. globalThis.atob = function (input) {
  33. // eslint-disable-next-line no-undef
  34. return Buffer.from(input, "base64").toString("binary");
  35. };
  36. })();
  37. // Support: Node.js
  38. (function checkDOMMatrix() {
  39. if (globalThis.DOMMatrix || !isNodeJS) {
  40. return;
  41. }
  42. globalThis.DOMMatrix = __non_webpack_require__("canvas").DOMMatrix;
  43. })();
  44. // Support: Node.js
  45. (function checkReadableStream() {
  46. if (globalThis.ReadableStream || !isNodeJS) {
  47. return;
  48. }
  49. globalThis.ReadableStream = __non_webpack_require__(
  50. "web-streams-polyfill/dist/ponyfill.js"
  51. ).ReadableStream;
  52. })();
  53. // Support: Firefox<90, Chrome<92, Safari<15.4, Node.js<16.6.0
  54. (function checkArrayAt() {
  55. if (Array.prototype.at) {
  56. return;
  57. }
  58. require("core-js/es/array/at.js");
  59. })();
  60. // Support: Firefox<90, Chrome<92, Safari<15.4, Node.js<16.6.0
  61. (function checkTypedArrayAt() {
  62. if (Uint8Array.prototype.at) {
  63. return;
  64. }
  65. require("core-js/es/typed-array/at.js");
  66. })();
  67. // Support: Firefox<94, Chrome<98, Safari<15.4, Node.js<17.0.0
  68. (function checkStructuredClone() {
  69. if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) {
  70. // The current image decoders are synchronous, hence `structuredClone`
  71. // shouldn't need to be polyfilled for the IMAGE_DECODERS build target.
  72. return;
  73. }
  74. if (globalThis.structuredClone) {
  75. return;
  76. }
  77. require("core-js/web/structured-clone.js");
  78. })();