| 1 |
"use strict"; |
| 2 |
var wp; |
| 3 |
(wp ||= {}).blob = (() => { |
| 4 |
var __defProp = Object.defineProperty; |
| 5 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 6 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
| 7 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 8 |
var __export = (target, all) => { |
| 9 |
for (var name in all) |
| 10 |
__defProp(target, name, { get: all[name], enumerable: true }); |
| 11 |
}; |
| 12 |
var __copyProps = (to, from, except, desc) => { |
| 13 |
if (from && typeof from === "object" || typeof from === "function") { |
| 14 |
for (let key of __getOwnPropNames(from)) |
| 15 |
if (!__hasOwnProp.call(to, key) && key !== except) |
| 16 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 17 |
} |
| 18 |
return to; |
| 19 |
}; |
| 20 |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
| 21 |
|
| 22 |
// packages/blob/build-module/index.mjs |
| 23 |
var index_exports = {}; |
| 24 |
__export(index_exports, { |
| 25 |
createBlobURL: () => createBlobURL, |
| 26 |
downloadBlob: () => downloadBlob, |
| 27 |
getBlobByURL: () => getBlobByURL, |
| 28 |
getBlobTypeByURL: () => getBlobTypeByURL, |
| 29 |
isBlobURL: () => isBlobURL, |
| 30 |
revokeBlobURL: () => revokeBlobURL |
| 31 |
}); |
| 32 |
var cache = {}; |
| 33 |
function createBlobURL(file) { |
| 34 |
const url = window.URL.createObjectURL(file); |
| 35 |
cache[url] = file; |
| 36 |
return url; |
| 37 |
} |
| 38 |
function getBlobByURL(url) { |
| 39 |
return cache[url]; |
| 40 |
} |
| 41 |
function getBlobTypeByURL(url) { |
| 42 |
return getBlobByURL(url)?.type.split("/")[0]; |
| 43 |
} |
| 44 |
function revokeBlobURL(url) { |
| 45 |
if (cache[url]) { |
| 46 |
window.URL.revokeObjectURL(url); |
| 47 |
} |
| 48 |
delete cache[url]; |
| 49 |
} |
| 50 |
function isBlobURL(url) { |
| 51 |
if (!url || !url.indexOf) { |
| 52 |
return false; |
| 53 |
} |
| 54 |
return url.indexOf("blob:") === 0; |
| 55 |
} |
| 56 |
function downloadBlob(filename, content, contentType = "") { |
| 57 |
if (!filename || !content) { |
| 58 |
return; |
| 59 |
} |
| 60 |
const file = new window.Blob([content], { type: contentType }); |
| 61 |
const url = window.URL.createObjectURL(file); |
| 62 |
const anchorElement = document.createElement("a"); |
| 63 |
anchorElement.href = url; |
| 64 |
anchorElement.download = filename; |
| 65 |
anchorElement.style.display = "none"; |
| 66 |
document.body.appendChild(anchorElement); |
| 67 |
anchorElement.click(); |
| 68 |
document.body.removeChild(anchorElement); |
| 69 |
window.URL.revokeObjectURL(url); |
| 70 |
} |
| 71 |
return __toCommonJS(index_exports); |
| 72 |
})(); |
| 73 |
//# sourceMappingURL=index.js.map |
| 74 |
|