[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /******/ (() => { // webpackBootstrap 2 /******/ "use strict"; 3 /******/ // The require scope 4 /******/ var __webpack_require__ = {}; 5 /******/ 6 /************************************************************************/ 7 /******/ /* webpack/runtime/define property getters */ 8 /******/ (() => { 9 /******/ // define getter functions for harmony exports 10 /******/ __webpack_require__.d = (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 /******/ (() => { 21 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22 /******/ })(); 23 /******/ 24 /******/ /* webpack/runtime/make namespace object */ 25 /******/ (() => { 26 /******/ // define __esModule on exports 27 /******/ __webpack_require__.r = (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: () => (/* binding */ createBlobURL), 40 /* harmony export */ downloadBlob: () => (/* binding */ downloadBlob), 41 /* harmony export */ getBlobByURL: () => (/* binding */ getBlobByURL), 42 /* harmony export */ getBlobTypeByURL: () => (/* binding */ getBlobTypeByURL), 43 /* harmony export */ isBlobURL: () => (/* binding */ isBlobURL), 44 /* harmony export */ revokeBlobURL: () => (/* binding */ revokeBlobURL) 45 /* harmony export */ }); 46 /** 47 * @type {Record<string, File|undefined>} 48 */ 49 const cache = {}; 50 51 /** 52 * Create a blob URL from a file. 53 * 54 * @param {File} file The file to create a blob URL for. 55 * 56 * @return {string} The blob URL. 57 */ 58 function createBlobURL(file) { 59 const url = window.URL.createObjectURL(file); 60 cache[url] = file; 61 return url; 62 } 63 64 /** 65 * Retrieve a file based on a blob URL. The file must have been created by 66 * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return 67 * `undefined`. 68 * 69 * @param {string} url The blob URL. 70 * 71 * @return {File|undefined} The file for the blob URL. 72 */ 73 function getBlobByURL(url) { 74 return cache[url]; 75 } 76 77 /** 78 * Retrieve a blob type based on URL. The file must have been created by 79 * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return 80 * `undefined`. 81 * 82 * @param {string} url The blob URL. 83 * 84 * @return {string|undefined} The blob type. 85 */ 86 function getBlobTypeByURL(url) { 87 return getBlobByURL(url)?.type.split('/')[0]; // 0: media type , 1: file extension eg ( type: 'image/jpeg' ). 88 } 89 90 /** 91 * Remove the resource and file cache from memory. 92 * 93 * @param {string} url The blob URL. 94 */ 95 function revokeBlobURL(url) { 96 if (cache[url]) { 97 window.URL.revokeObjectURL(url); 98 } 99 delete cache[url]; 100 } 101 102 /** 103 * Check whether a url is a blob url. 104 * 105 * @param {string|undefined} url The URL. 106 * 107 * @return {boolean} Is the url a blob url? 108 */ 109 function isBlobURL(url) { 110 if (!url || !url.indexOf) { 111 return false; 112 } 113 return url.indexOf('blob:') === 0; 114 } 115 116 /** 117 * Downloads a file, e.g., a text or readable stream, in the browser. 118 * Appropriate for downloading smaller file sizes, e.g., < 5 MB. 119 * 120 * Example usage: 121 * 122 * ```js 123 * const fileContent = JSON.stringify( 124 * { 125 * "title": "My Post", 126 * }, 127 * null, 128 * 2 129 * ); 130 * const filename = 'file.json'; 131 * 132 * downloadBlob( filename, fileContent, 'application/json' ); 133 * ``` 134 * 135 * @param {string} filename File name. 136 * @param {BlobPart} content File content (BufferSource | Blob | string). 137 * @param {string} contentType (Optional) File mime type. Default is `''`. 138 */ 139 function downloadBlob(filename, content, contentType = '') { 140 if (!filename || !content) { 141 return; 142 } 143 const file = new window.Blob([content], { 144 type: contentType 145 }); 146 const url = window.URL.createObjectURL(file); 147 const anchorElement = document.createElement('a'); 148 anchorElement.href = url; 149 anchorElement.download = filename; 150 anchorElement.style.display = 'none'; 151 document.body.appendChild(anchorElement); 152 anchorElement.click(); 153 document.body.removeChild(anchorElement); 154 window.URL.revokeObjectURL(url); 155 } 156 157 (window.wp = window.wp || {}).blob = __webpack_exports__; 158 /******/ })() 159 ;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Tue Mar 19 08:20:01 2024 | Cross-referenced by PHPXref |