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.

116 lines
3.6 KiB

1 year ago
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(exports, definition) {
  11. /******/ for(var key in definition) {
  12. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14. /******/ }
  15. /******/ }
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  20. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /******/ /* webpack/runtime/make namespace object */
  25. /******/ !function() {
  26. /******/ // define __esModule on exports
  27. /******/ __webpack_require__.r = function(exports) {
  28. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30. /******/ }
  31. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  32. /******/ };
  33. /******/ }();
  34. /******/
  35. /************************************************************************/
  36. var __webpack_exports__ = {};
  37. __webpack_require__.r(__webpack_exports__);
  38. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  39. /* harmony export */ createBlobURL: function() { return /* binding */ createBlobURL; },
  40. /* harmony export */ getBlobByURL: function() { return /* binding */ getBlobByURL; },
  41. /* harmony export */ getBlobTypeByURL: function() { return /* binding */ getBlobTypeByURL; },
  42. /* harmony export */ isBlobURL: function() { return /* binding */ isBlobURL; },
  43. /* harmony export */ revokeBlobURL: function() { return /* binding */ revokeBlobURL; }
  44. /* harmony export */ });
  45. /**
  46. * @type {Record<string, File|undefined>}
  47. */
  48. const cache = {};
  49. /**
  50. * Create a blob URL from a file.
  51. *
  52. * @param {File} file The file to create a blob URL for.
  53. *
  54. * @return {string} The blob URL.
  55. */
  56. function createBlobURL(file) {
  57. const url = window.URL.createObjectURL(file);
  58. cache[url] = file;
  59. return url;
  60. }
  61. /**
  62. * Retrieve a file based on a blob URL. The file must have been created by
  63. * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
  64. * `undefined`.
  65. *
  66. * @param {string} url The blob URL.
  67. *
  68. * @return {File|undefined} The file for the blob URL.
  69. */
  70. function getBlobByURL(url) {
  71. return cache[url];
  72. }
  73. /**
  74. * Retrieve a blob type based on URL. The file must have been created by
  75. * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
  76. * `undefined`.
  77. *
  78. * @param {string} url The blob URL.
  79. *
  80. * @return {string|undefined} The blob type.
  81. */
  82. function getBlobTypeByURL(url) {
  83. return getBlobByURL(url)?.type.split('/')[0]; // 0: media type , 1: file extension eg ( type: 'image/jpeg' ).
  84. }
  85. /**
  86. * Remove the resource and file cache from memory.
  87. *
  88. * @param {string} url The blob URL.
  89. */
  90. function revokeBlobURL(url) {
  91. if (cache[url]) {
  92. window.URL.revokeObjectURL(url);
  93. }
  94. delete cache[url];
  95. }
  96. /**
  97. * Check whether a url is a blob url.
  98. *
  99. * @param {string|undefined} url The URL.
  100. *
  101. * @return {boolean} Is the url a blob url?
  102. */
  103. function isBlobURL(url) {
  104. if (!url || !url.indexOf) {
  105. return false;
  106. }
  107. return url.indexOf('blob:') === 0;
  108. }
  109. (window.wp = window.wp || {}).blob = __webpack_exports__;
  110. /******/ })()
  111. ;