You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. import 'intl';
  2. import 'intl/locale-data/jsonp/en';
  3. import 'es6-symbol/implement';
  4. import includes from 'array-includes';
  5. import assign from 'object-assign';
  6. import values from 'object.values';
  7. import isNaN from 'is-nan';
  8. import { decode as decodeBase64 } from './utils/base64';
  9. import promiseFinally from 'promise.prototype.finally';
  10. if (!Array.prototype.includes) {
  11. includes.shim();
  12. }
  13. if (!Object.assign) {
  14. Object.assign = assign;
  15. }
  16. if (!Object.values) {
  17. values.shim();
  18. }
  19. if (!Number.isNaN) {
  20. Number.isNaN = isNaN;
  21. }
  22. promiseFinally.shim();
  23. if (!HTMLCanvasElement.prototype.toBlob) {
  24. const BASE64_MARKER = ';base64,';
  25. Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
  26. value(callback, type = 'image/png', quality) {
  27. const dataURL = this.toDataURL(type, quality);
  28. let data;
  29. if (dataURL.indexOf(BASE64_MARKER) >= 0) {
  30. const [, base64] = dataURL.split(BASE64_MARKER);
  31. data = decodeBase64(base64);
  32. } else {
  33. [, data] = dataURL.split(',');
  34. }
  35. callback(new Blob([data], { type }));
  36. },
  37. });
  38. }