@wordpress/blob 4.32.0 → 4.32.1-next.47f435fc9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -1,120 +1,77 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
-
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_exports = {};
20
+ __export(index_exports, {
21
+ createBlobURL: () => createBlobURL,
22
+ downloadBlob: () => downloadBlob,
23
+ getBlobByURL: () => getBlobByURL,
24
+ getBlobTypeByURL: () => getBlobTypeByURL,
25
+ isBlobURL: () => isBlobURL,
26
+ revokeBlobURL: () => revokeBlobURL
6
27
  });
7
- exports.createBlobURL = createBlobURL;
8
- exports.downloadBlob = downloadBlob;
9
- exports.getBlobByURL = getBlobByURL;
10
- exports.getBlobTypeByURL = getBlobTypeByURL;
11
- exports.isBlobURL = isBlobURL;
12
- exports.revokeBlobURL = revokeBlobURL;
28
+ module.exports = __toCommonJS(index_exports);
13
29
  const cache = {};
14
-
15
- /**
16
- * Create a blob URL from a file.
17
- *
18
- * @param file The file to create a blob URL for.
19
- *
20
- * @return The blob URL.
21
- */
22
30
  function createBlobURL(file) {
23
31
  const url = window.URL.createObjectURL(file);
24
32
  cache[url] = file;
25
33
  return url;
26
34
  }
27
-
28
- /**
29
- * Retrieve a file based on a blob URL. The file must have been created by
30
- * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
31
- * `undefined`.
32
- *
33
- * @param url The blob URL.
34
- *
35
- * @return The file for the blob URL.
36
- */
37
35
  function getBlobByURL(url) {
38
36
  return cache[url];
39
37
  }
40
-
41
- /**
42
- * Retrieve a blob type based on URL. The file must have been created by
43
- * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
44
- * `undefined`.
45
- *
46
- * @param url The blob URL.
47
- *
48
- * @return The blob type.
49
- */
50
38
  function getBlobTypeByURL(url) {
51
- return getBlobByURL(url)?.type.split('/')[0]; // 0: media type , 1: file extension eg ( type: 'image/jpeg' ).
39
+ return getBlobByURL(url)?.type.split("/")[0];
52
40
  }
53
-
54
- /**
55
- * Remove the resource and file cache from memory.
56
- *
57
- * @param url The blob URL.
58
- */
59
41
  function revokeBlobURL(url) {
60
42
  if (cache[url]) {
61
43
  window.URL.revokeObjectURL(url);
62
44
  }
63
45
  delete cache[url];
64
46
  }
65
-
66
- /**
67
- * Check whether a url is a blob url.
68
- *
69
- * @param url The URL.
70
- *
71
- * @return Is the url a blob url?
72
- */
73
47
  function isBlobURL(url) {
74
48
  if (!url || !url.indexOf) {
75
49
  return false;
76
50
  }
77
- return url.indexOf('blob:') === 0;
51
+ return url.indexOf("blob:") === 0;
78
52
  }
79
-
80
- /**
81
- * Downloads a file, e.g., a text or readable stream, in the browser.
82
- * Appropriate for downloading smaller file sizes, e.g., < 5 MB.
83
- *
84
- * Example usage:
85
- *
86
- * ```js
87
- * const fileContent = JSON.stringify(
88
- * {
89
- * "title": "My Post",
90
- * },
91
- * null,
92
- * 2
93
- * );
94
- * const filename = 'file.json';
95
- *
96
- * downloadBlob( filename, fileContent, 'application/json' );
97
- * ```
98
- *
99
- * @param filename File name.
100
- * @param content File content (BufferSource | Blob | string).
101
- * @param contentType (Optional) File mime type. Default is `''`.
102
- */
103
- function downloadBlob(filename, content, contentType = '') {
53
+ function downloadBlob(filename, content, contentType = "") {
104
54
  if (!filename || !content) {
105
55
  return;
106
56
  }
107
- const file = new window.Blob([content], {
108
- type: contentType
109
- });
57
+ const file = new window.Blob([content], { type: contentType });
110
58
  const url = window.URL.createObjectURL(file);
111
- const anchorElement = document.createElement('a');
59
+ const anchorElement = document.createElement("a");
112
60
  anchorElement.href = url;
113
61
  anchorElement.download = filename;
114
- anchorElement.style.display = 'none';
62
+ anchorElement.style.display = "none";
115
63
  document.body.appendChild(anchorElement);
116
64
  anchorElement.click();
117
65
  document.body.removeChild(anchorElement);
118
66
  window.URL.revokeObjectURL(url);
119
67
  }
120
- //# sourceMappingURL=index.js.map
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ createBlobURL,
71
+ downloadBlob,
72
+ getBlobByURL,
73
+ getBlobTypeByURL,
74
+ isBlobURL,
75
+ revokeBlobURL
76
+ });
77
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["cache","createBlobURL","file","url","window","URL","createObjectURL","getBlobByURL","getBlobTypeByURL","type","split","revokeBlobURL","revokeObjectURL","isBlobURL","indexOf","downloadBlob","filename","content","contentType","Blob","anchorElement","document","createElement","href","download","style","display","body","appendChild","click","removeChild"],"sources":["@wordpress/blob/src/index.ts"],"sourcesContent":["const cache: Record< string, File > = {};\n\n/**\n * Create a blob URL from a file.\n *\n * @param file The file to create a blob URL for.\n *\n * @return The blob URL.\n */\nexport function createBlobURL( file: File ): string {\n\tconst url = window.URL.createObjectURL( file );\n\n\tcache[ url ] = file;\n\n\treturn url;\n}\n\n/**\n * Retrieve a file based on a blob URL. The file must have been created by\n * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return\n * `undefined`.\n *\n * @param url The blob URL.\n *\n * @return The file for the blob URL.\n */\nexport function getBlobByURL( url: string ): File | undefined {\n\treturn cache[ url ];\n}\n\n/**\n * Retrieve a blob type based on URL. The file must have been created by\n * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return\n * `undefined`.\n *\n * @param url The blob URL.\n *\n * @return The blob type.\n */\nexport function getBlobTypeByURL( url: string ): string | undefined {\n\treturn getBlobByURL( url )?.type.split( '/' )[ 0 ]; // 0: media type , 1: file extension eg ( type: 'image/jpeg' ).\n}\n\n/**\n * Remove the resource and file cache from memory.\n *\n * @param url The blob URL.\n */\nexport function revokeBlobURL( url: string ): void {\n\tif ( cache[ url ] ) {\n\t\twindow.URL.revokeObjectURL( url );\n\t}\n\n\tdelete cache[ url ];\n}\n\n/**\n * Check whether a url is a blob url.\n *\n * @param url The URL.\n *\n * @return Is the url a blob url?\n */\nexport function isBlobURL( url: string | undefined ): boolean {\n\tif ( ! url || ! url.indexOf ) {\n\t\treturn false;\n\t}\n\treturn url.indexOf( 'blob:' ) === 0;\n}\n\n/**\n * Downloads a file, e.g., a text or readable stream, in the browser.\n * Appropriate for downloading smaller file sizes, e.g., < 5 MB.\n *\n * Example usage:\n *\n * ```js\n * \tconst fileContent = JSON.stringify(\n * \t\t{\n * \t\t\t\"title\": \"My Post\",\n * \t\t},\n * \t\tnull,\n * \t\t2\n * \t);\n * \tconst filename = 'file.json';\n *\n * \tdownloadBlob( filename, fileContent, 'application/json' );\n * ```\n *\n * @param filename File name.\n * @param content File content (BufferSource | Blob | string).\n * @param contentType (Optional) File mime type. Default is `''`.\n */\nexport function downloadBlob(\n\tfilename: string,\n\tcontent: BlobPart,\n\tcontentType: string = ''\n): void {\n\tif ( ! filename || ! content ) {\n\t\treturn;\n\t}\n\n\tconst file = new window.Blob( [ content ], { type: contentType } );\n\tconst url = window.URL.createObjectURL( file );\n\tconst anchorElement = document.createElement( 'a' );\n\tanchorElement.href = url;\n\tanchorElement.download = filename;\n\tanchorElement.style.display = 'none';\n\tdocument.body.appendChild( anchorElement );\n\tanchorElement.click();\n\tdocument.body.removeChild( anchorElement );\n\twindow.URL.revokeObjectURL( url );\n}\n"],"mappings":";;;;;;;;;;;;AAAA,MAAMA,KAA6B,GAAG,CAAC,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAAEC,IAAU,EAAW;EACnD,MAAMC,GAAG,GAAGC,MAAM,CAACC,GAAG,CAACC,eAAe,CAAEJ,IAAK,CAAC;EAE9CF,KAAK,CAAEG,GAAG,CAAE,GAAGD,IAAI;EAEnB,OAAOC,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,YAAYA,CAAEJ,GAAW,EAAqB;EAC7D,OAAOH,KAAK,CAAEG,GAAG,CAAE;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASK,gBAAgBA,CAAEL,GAAW,EAAuB;EACnE,OAAOI,YAAY,CAAEJ,GAAI,CAAC,EAAEM,IAAI,CAACC,KAAK,CAAE,GAAI,CAAC,CAAE,CAAC,CAAE,CAAC,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAAER,GAAW,EAAS;EAClD,IAAKH,KAAK,CAAEG,GAAG,CAAE,EAAG;IACnBC,MAAM,CAACC,GAAG,CAACO,eAAe,CAAET,GAAI,CAAC;EAClC;EAEA,OAAOH,KAAK,CAAEG,GAAG,CAAE;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASU,SAASA,CAAEV,GAAuB,EAAY;EAC7D,IAAK,CAAEA,GAAG,IAAI,CAAEA,GAAG,CAACW,OAAO,EAAG;IAC7B,OAAO,KAAK;EACb;EACA,OAAOX,GAAG,CAACW,OAAO,CAAE,OAAQ,CAAC,KAAK,CAAC;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAC3BC,QAAgB,EAChBC,OAAiB,EACjBC,WAAmB,GAAG,EAAE,EACjB;EACP,IAAK,CAAEF,QAAQ,IAAI,CAAEC,OAAO,EAAG;IAC9B;EACD;EAEA,MAAMf,IAAI,GAAG,IAAIE,MAAM,CAACe,IAAI,CAAE,CAAEF,OAAO,CAAE,EAAE;IAAER,IAAI,EAAES;EAAY,CAAE,CAAC;EAClE,MAAMf,GAAG,GAAGC,MAAM,CAACC,GAAG,CAACC,eAAe,CAAEJ,IAAK,CAAC;EAC9C,MAAMkB,aAAa,GAAGC,QAAQ,CAACC,aAAa,CAAE,GAAI,CAAC;EACnDF,aAAa,CAACG,IAAI,GAAGpB,GAAG;EACxBiB,aAAa,CAACI,QAAQ,GAAGR,QAAQ;EACjCI,aAAa,CAACK,KAAK,CAACC,OAAO,GAAG,MAAM;EACpCL,QAAQ,CAACM,IAAI,CAACC,WAAW,CAAER,aAAc,CAAC;EAC1CA,aAAa,CAACS,KAAK,CAAC,CAAC;EACrBR,QAAQ,CAACM,IAAI,CAACG,WAAW,CAAEV,aAAc,CAAC;EAC1ChB,MAAM,CAACC,GAAG,CAACO,eAAe,CAAET,GAAI,CAAC;AAClC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["const cache: Record< string, File > = {};\n\n/**\n * Create a blob URL from a file.\n *\n * @param file The file to create a blob URL for.\n *\n * @return The blob URL.\n */\nexport function createBlobURL( file: File ): string {\n\tconst url = window.URL.createObjectURL( file );\n\n\tcache[ url ] = file;\n\n\treturn url;\n}\n\n/**\n * Retrieve a file based on a blob URL. The file must have been created by\n * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return\n * `undefined`.\n *\n * @param url The blob URL.\n *\n * @return The file for the blob URL.\n */\nexport function getBlobByURL( url: string ): File | undefined {\n\treturn cache[ url ];\n}\n\n/**\n * Retrieve a blob type based on URL. The file must have been created by\n * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return\n * `undefined`.\n *\n * @param url The blob URL.\n *\n * @return The blob type.\n */\nexport function getBlobTypeByURL( url: string ): string | undefined {\n\treturn getBlobByURL( url )?.type.split( '/' )[ 0 ]; // 0: media type , 1: file extension eg ( type: 'image/jpeg' ).\n}\n\n/**\n * Remove the resource and file cache from memory.\n *\n * @param url The blob URL.\n */\nexport function revokeBlobURL( url: string ): void {\n\tif ( cache[ url ] ) {\n\t\twindow.URL.revokeObjectURL( url );\n\t}\n\n\tdelete cache[ url ];\n}\n\n/**\n * Check whether a url is a blob url.\n *\n * @param url The URL.\n *\n * @return Is the url a blob url?\n */\nexport function isBlobURL( url: string | undefined ): boolean {\n\tif ( ! url || ! url.indexOf ) {\n\t\treturn false;\n\t}\n\treturn url.indexOf( 'blob:' ) === 0;\n}\n\n/**\n * Downloads a file, e.g., a text or readable stream, in the browser.\n * Appropriate for downloading smaller file sizes, e.g., < 5 MB.\n *\n * Example usage:\n *\n * ```js\n * \tconst fileContent = JSON.stringify(\n * \t\t{\n * \t\t\t\"title\": \"My Post\",\n * \t\t},\n * \t\tnull,\n * \t\t2\n * \t);\n * \tconst filename = 'file.json';\n *\n * \tdownloadBlob( filename, fileContent, 'application/json' );\n * ```\n *\n * @param filename File name.\n * @param content File content (BufferSource | Blob | string).\n * @param contentType (Optional) File mime type. Default is `''`.\n */\nexport function downloadBlob(\n\tfilename: string,\n\tcontent: BlobPart,\n\tcontentType: string = ''\n): void {\n\tif ( ! filename || ! content ) {\n\t\treturn;\n\t}\n\n\tconst file = new window.Blob( [ content ], { type: contentType } );\n\tconst url = window.URL.createObjectURL( file );\n\tconst anchorElement = document.createElement( 'a' );\n\tanchorElement.href = url;\n\tanchorElement.download = filename;\n\tanchorElement.style.display = 'none';\n\tdocument.body.appendChild( anchorElement );\n\tanchorElement.click();\n\tdocument.body.removeChild( anchorElement );\n\twindow.URL.revokeObjectURL( url );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,QAAgC,CAAC;AAShC,SAAS,cAAe,MAAqB;AACnD,QAAM,MAAM,OAAO,IAAI,gBAAiB,IAAK;AAE7C,QAAO,GAAI,IAAI;AAEf,SAAO;AACR;AAWO,SAAS,aAAc,KAAgC;AAC7D,SAAO,MAAO,GAAI;AACnB;AAWO,SAAS,iBAAkB,KAAkC;AACnE,SAAO,aAAc,GAAI,GAAG,KAAK,MAAO,GAAI,EAAG,CAAE;AAClD;AAOO,SAAS,cAAe,KAAoB;AAClD,MAAK,MAAO,GAAI,GAAI;AACnB,WAAO,IAAI,gBAAiB,GAAI;AAAA,EACjC;AAEA,SAAO,MAAO,GAAI;AACnB;AASO,SAAS,UAAW,KAAmC;AAC7D,MAAK,CAAE,OAAO,CAAE,IAAI,SAAU;AAC7B,WAAO;AAAA,EACR;AACA,SAAO,IAAI,QAAS,OAAQ,MAAM;AACnC;AAyBO,SAAS,aACf,UACA,SACA,cAAsB,IACf;AACP,MAAK,CAAE,YAAY,CAAE,SAAU;AAC9B;AAAA,EACD;AAEA,QAAM,OAAO,IAAI,OAAO,KAAM,CAAE,OAAQ,GAAG,EAAE,MAAM,YAAY,CAAE;AACjE,QAAM,MAAM,OAAO,IAAI,gBAAiB,IAAK;AAC7C,QAAM,gBAAgB,SAAS,cAAe,GAAI;AAClD,gBAAc,OAAO;AACrB,gBAAc,WAAW;AACzB,gBAAc,MAAM,UAAU;AAC9B,WAAS,KAAK,YAAa,aAAc;AACzC,gBAAc,MAAM;AACpB,WAAS,KAAK,YAAa,aAAc;AACzC,SAAO,IAAI,gBAAiB,GAAI;AACjC;",
6
+ "names": []
7
+ }
@@ -1,109 +1,48 @@
1
- /* wp:polyfill */
2
1
  const cache = {};
3
-
4
- /**
5
- * Create a blob URL from a file.
6
- *
7
- * @param file The file to create a blob URL for.
8
- *
9
- * @return The blob URL.
10
- */
11
- export function createBlobURL(file) {
2
+ function createBlobURL(file) {
12
3
  const url = window.URL.createObjectURL(file);
13
4
  cache[url] = file;
14
5
  return url;
15
6
  }
16
-
17
- /**
18
- * Retrieve a file based on a blob URL. The file must have been created by
19
- * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
20
- * `undefined`.
21
- *
22
- * @param url The blob URL.
23
- *
24
- * @return The file for the blob URL.
25
- */
26
- export function getBlobByURL(url) {
7
+ function getBlobByURL(url) {
27
8
  return cache[url];
28
9
  }
29
-
30
- /**
31
- * Retrieve a blob type based on URL. The file must have been created by
32
- * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
33
- * `undefined`.
34
- *
35
- * @param url The blob URL.
36
- *
37
- * @return The blob type.
38
- */
39
- export function getBlobTypeByURL(url) {
40
- return getBlobByURL(url)?.type.split('/')[0]; // 0: media type , 1: file extension eg ( type: 'image/jpeg' ).
10
+ function getBlobTypeByURL(url) {
11
+ return getBlobByURL(url)?.type.split("/")[0];
41
12
  }
42
-
43
- /**
44
- * Remove the resource and file cache from memory.
45
- *
46
- * @param url The blob URL.
47
- */
48
- export function revokeBlobURL(url) {
13
+ function revokeBlobURL(url) {
49
14
  if (cache[url]) {
50
15
  window.URL.revokeObjectURL(url);
51
16
  }
52
17
  delete cache[url];
53
18
  }
54
-
55
- /**
56
- * Check whether a url is a blob url.
57
- *
58
- * @param url The URL.
59
- *
60
- * @return Is the url a blob url?
61
- */
62
- export function isBlobURL(url) {
19
+ function isBlobURL(url) {
63
20
  if (!url || !url.indexOf) {
64
21
  return false;
65
22
  }
66
- return url.indexOf('blob:') === 0;
23
+ return url.indexOf("blob:") === 0;
67
24
  }
68
-
69
- /**
70
- * Downloads a file, e.g., a text or readable stream, in the browser.
71
- * Appropriate for downloading smaller file sizes, e.g., < 5 MB.
72
- *
73
- * Example usage:
74
- *
75
- * ```js
76
- * const fileContent = JSON.stringify(
77
- * {
78
- * "title": "My Post",
79
- * },
80
- * null,
81
- * 2
82
- * );
83
- * const filename = 'file.json';
84
- *
85
- * downloadBlob( filename, fileContent, 'application/json' );
86
- * ```
87
- *
88
- * @param filename File name.
89
- * @param content File content (BufferSource | Blob | string).
90
- * @param contentType (Optional) File mime type. Default is `''`.
91
- */
92
- export function downloadBlob(filename, content, contentType = '') {
25
+ function downloadBlob(filename, content, contentType = "") {
93
26
  if (!filename || !content) {
94
27
  return;
95
28
  }
96
- const file = new window.Blob([content], {
97
- type: contentType
98
- });
29
+ const file = new window.Blob([content], { type: contentType });
99
30
  const url = window.URL.createObjectURL(file);
100
- const anchorElement = document.createElement('a');
31
+ const anchorElement = document.createElement("a");
101
32
  anchorElement.href = url;
102
33
  anchorElement.download = filename;
103
- anchorElement.style.display = 'none';
34
+ anchorElement.style.display = "none";
104
35
  document.body.appendChild(anchorElement);
105
36
  anchorElement.click();
106
37
  document.body.removeChild(anchorElement);
107
38
  window.URL.revokeObjectURL(url);
108
39
  }
109
- //# sourceMappingURL=index.js.map
40
+ export {
41
+ createBlobURL,
42
+ downloadBlob,
43
+ getBlobByURL,
44
+ getBlobTypeByURL,
45
+ isBlobURL,
46
+ revokeBlobURL
47
+ };
48
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["cache","createBlobURL","file","url","window","URL","createObjectURL","getBlobByURL","getBlobTypeByURL","type","split","revokeBlobURL","revokeObjectURL","isBlobURL","indexOf","downloadBlob","filename","content","contentType","Blob","anchorElement","document","createElement","href","download","style","display","body","appendChild","click","removeChild"],"sources":["@wordpress/blob/src/index.ts"],"sourcesContent":["const cache: Record< string, File > = {};\n\n/**\n * Create a blob URL from a file.\n *\n * @param file The file to create a blob URL for.\n *\n * @return The blob URL.\n */\nexport function createBlobURL( file: File ): string {\n\tconst url = window.URL.createObjectURL( file );\n\n\tcache[ url ] = file;\n\n\treturn url;\n}\n\n/**\n * Retrieve a file based on a blob URL. The file must have been created by\n * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return\n * `undefined`.\n *\n * @param url The blob URL.\n *\n * @return The file for the blob URL.\n */\nexport function getBlobByURL( url: string ): File | undefined {\n\treturn cache[ url ];\n}\n\n/**\n * Retrieve a blob type based on URL. The file must have been created by\n * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return\n * `undefined`.\n *\n * @param url The blob URL.\n *\n * @return The blob type.\n */\nexport function getBlobTypeByURL( url: string ): string | undefined {\n\treturn getBlobByURL( url )?.type.split( '/' )[ 0 ]; // 0: media type , 1: file extension eg ( type: 'image/jpeg' ).\n}\n\n/**\n * Remove the resource and file cache from memory.\n *\n * @param url The blob URL.\n */\nexport function revokeBlobURL( url: string ): void {\n\tif ( cache[ url ] ) {\n\t\twindow.URL.revokeObjectURL( url );\n\t}\n\n\tdelete cache[ url ];\n}\n\n/**\n * Check whether a url is a blob url.\n *\n * @param url The URL.\n *\n * @return Is the url a blob url?\n */\nexport function isBlobURL( url: string | undefined ): boolean {\n\tif ( ! url || ! url.indexOf ) {\n\t\treturn false;\n\t}\n\treturn url.indexOf( 'blob:' ) === 0;\n}\n\n/**\n * Downloads a file, e.g., a text or readable stream, in the browser.\n * Appropriate for downloading smaller file sizes, e.g., < 5 MB.\n *\n * Example usage:\n *\n * ```js\n * \tconst fileContent = JSON.stringify(\n * \t\t{\n * \t\t\t\"title\": \"My Post\",\n * \t\t},\n * \t\tnull,\n * \t\t2\n * \t);\n * \tconst filename = 'file.json';\n *\n * \tdownloadBlob( filename, fileContent, 'application/json' );\n * ```\n *\n * @param filename File name.\n * @param content File content (BufferSource | Blob | string).\n * @param contentType (Optional) File mime type. Default is `''`.\n */\nexport function downloadBlob(\n\tfilename: string,\n\tcontent: BlobPart,\n\tcontentType: string = ''\n): void {\n\tif ( ! filename || ! content ) {\n\t\treturn;\n\t}\n\n\tconst file = new window.Blob( [ content ], { type: contentType } );\n\tconst url = window.URL.createObjectURL( file );\n\tconst anchorElement = document.createElement( 'a' );\n\tanchorElement.href = url;\n\tanchorElement.download = filename;\n\tanchorElement.style.display = 'none';\n\tdocument.body.appendChild( anchorElement );\n\tanchorElement.click();\n\tdocument.body.removeChild( anchorElement );\n\twindow.URL.revokeObjectURL( url );\n}\n"],"mappings":";AAAA,MAAMA,KAA6B,GAAG,CAAC,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAAEC,IAAU,EAAW;EACnD,MAAMC,GAAG,GAAGC,MAAM,CAACC,GAAG,CAACC,eAAe,CAAEJ,IAAK,CAAC;EAE9CF,KAAK,CAAEG,GAAG,CAAE,GAAGD,IAAI;EAEnB,OAAOC,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,YAAYA,CAAEJ,GAAW,EAAqB;EAC7D,OAAOH,KAAK,CAAEG,GAAG,CAAE;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,gBAAgBA,CAAEL,GAAW,EAAuB;EACnE,OAAOI,YAAY,CAAEJ,GAAI,CAAC,EAAEM,IAAI,CAACC,KAAK,CAAE,GAAI,CAAC,CAAE,CAAC,CAAE,CAAC,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAAER,GAAW,EAAS;EAClD,IAAKH,KAAK,CAAEG,GAAG,CAAE,EAAG;IACnBC,MAAM,CAACC,GAAG,CAACO,eAAe,CAAET,GAAI,CAAC;EAClC;EAEA,OAAOH,KAAK,CAAEG,GAAG,CAAE;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASU,SAASA,CAAEV,GAAuB,EAAY;EAC7D,IAAK,CAAEA,GAAG,IAAI,CAAEA,GAAG,CAACW,OAAO,EAAG;IAC7B,OAAO,KAAK;EACb;EACA,OAAOX,GAAG,CAACW,OAAO,CAAE,OAAQ,CAAC,KAAK,CAAC;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAC3BC,QAAgB,EAChBC,OAAiB,EACjBC,WAAmB,GAAG,EAAE,EACjB;EACP,IAAK,CAAEF,QAAQ,IAAI,CAAEC,OAAO,EAAG;IAC9B;EACD;EAEA,MAAMf,IAAI,GAAG,IAAIE,MAAM,CAACe,IAAI,CAAE,CAAEF,OAAO,CAAE,EAAE;IAAER,IAAI,EAAES;EAAY,CAAE,CAAC;EAClE,MAAMf,GAAG,GAAGC,MAAM,CAACC,GAAG,CAACC,eAAe,CAAEJ,IAAK,CAAC;EAC9C,MAAMkB,aAAa,GAAGC,QAAQ,CAACC,aAAa,CAAE,GAAI,CAAC;EACnDF,aAAa,CAACG,IAAI,GAAGpB,GAAG;EACxBiB,aAAa,CAACI,QAAQ,GAAGR,QAAQ;EACjCI,aAAa,CAACK,KAAK,CAACC,OAAO,GAAG,MAAM;EACpCL,QAAQ,CAACM,IAAI,CAACC,WAAW,CAAER,aAAc,CAAC;EAC1CA,aAAa,CAACS,KAAK,CAAC,CAAC;EACrBR,QAAQ,CAACM,IAAI,CAACG,WAAW,CAAEV,aAAc,CAAC;EAC1ChB,MAAM,CAACC,GAAG,CAACO,eAAe,CAAET,GAAI,CAAC;AAClC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["const cache: Record< string, File > = {};\n\n/**\n * Create a blob URL from a file.\n *\n * @param file The file to create a blob URL for.\n *\n * @return The blob URL.\n */\nexport function createBlobURL( file: File ): string {\n\tconst url = window.URL.createObjectURL( file );\n\n\tcache[ url ] = file;\n\n\treturn url;\n}\n\n/**\n * Retrieve a file based on a blob URL. The file must have been created by\n * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return\n * `undefined`.\n *\n * @param url The blob URL.\n *\n * @return The file for the blob URL.\n */\nexport function getBlobByURL( url: string ): File | undefined {\n\treturn cache[ url ];\n}\n\n/**\n * Retrieve a blob type based on URL. The file must have been created by\n * `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return\n * `undefined`.\n *\n * @param url The blob URL.\n *\n * @return The blob type.\n */\nexport function getBlobTypeByURL( url: string ): string | undefined {\n\treturn getBlobByURL( url )?.type.split( '/' )[ 0 ]; // 0: media type , 1: file extension eg ( type: 'image/jpeg' ).\n}\n\n/**\n * Remove the resource and file cache from memory.\n *\n * @param url The blob URL.\n */\nexport function revokeBlobURL( url: string ): void {\n\tif ( cache[ url ] ) {\n\t\twindow.URL.revokeObjectURL( url );\n\t}\n\n\tdelete cache[ url ];\n}\n\n/**\n * Check whether a url is a blob url.\n *\n * @param url The URL.\n *\n * @return Is the url a blob url?\n */\nexport function isBlobURL( url: string | undefined ): boolean {\n\tif ( ! url || ! url.indexOf ) {\n\t\treturn false;\n\t}\n\treturn url.indexOf( 'blob:' ) === 0;\n}\n\n/**\n * Downloads a file, e.g., a text or readable stream, in the browser.\n * Appropriate for downloading smaller file sizes, e.g., < 5 MB.\n *\n * Example usage:\n *\n * ```js\n * \tconst fileContent = JSON.stringify(\n * \t\t{\n * \t\t\t\"title\": \"My Post\",\n * \t\t},\n * \t\tnull,\n * \t\t2\n * \t);\n * \tconst filename = 'file.json';\n *\n * \tdownloadBlob( filename, fileContent, 'application/json' );\n * ```\n *\n * @param filename File name.\n * @param content File content (BufferSource | Blob | string).\n * @param contentType (Optional) File mime type. Default is `''`.\n */\nexport function downloadBlob(\n\tfilename: string,\n\tcontent: BlobPart,\n\tcontentType: string = ''\n): void {\n\tif ( ! filename || ! content ) {\n\t\treturn;\n\t}\n\n\tconst file = new window.Blob( [ content ], { type: contentType } );\n\tconst url = window.URL.createObjectURL( file );\n\tconst anchorElement = document.createElement( 'a' );\n\tanchorElement.href = url;\n\tanchorElement.download = filename;\n\tanchorElement.style.display = 'none';\n\tdocument.body.appendChild( anchorElement );\n\tanchorElement.click();\n\tdocument.body.removeChild( anchorElement );\n\twindow.URL.revokeObjectURL( url );\n}\n"],
5
+ "mappings": "AAAA,MAAM,QAAgC,CAAC;AAShC,SAAS,cAAe,MAAqB;AACnD,QAAM,MAAM,OAAO,IAAI,gBAAiB,IAAK;AAE7C,QAAO,GAAI,IAAI;AAEf,SAAO;AACR;AAWO,SAAS,aAAc,KAAgC;AAC7D,SAAO,MAAO,GAAI;AACnB;AAWO,SAAS,iBAAkB,KAAkC;AACnE,SAAO,aAAc,GAAI,GAAG,KAAK,MAAO,GAAI,EAAG,CAAE;AAClD;AAOO,SAAS,cAAe,KAAoB;AAClD,MAAK,MAAO,GAAI,GAAI;AACnB,WAAO,IAAI,gBAAiB,GAAI;AAAA,EACjC;AAEA,SAAO,MAAO,GAAI;AACnB;AASO,SAAS,UAAW,KAAmC;AAC7D,MAAK,CAAE,OAAO,CAAE,IAAI,SAAU;AAC7B,WAAO;AAAA,EACR;AACA,SAAO,IAAI,QAAS,OAAQ,MAAM;AACnC;AAyBO,SAAS,aACf,UACA,SACA,cAAsB,IACf;AACP,MAAK,CAAE,YAAY,CAAE,SAAU;AAC9B;AAAA,EACD;AAEA,QAAM,OAAO,IAAI,OAAO,KAAM,CAAE,OAAQ,GAAG,EAAE,MAAM,YAAY,CAAE;AACjE,QAAM,MAAM,OAAO,IAAI,gBAAiB,IAAK;AAC7C,QAAM,gBAAgB,SAAS,cAAe,GAAI;AAClD,gBAAc,OAAO;AACrB,gBAAc,WAAW;AACzB,gBAAc,MAAM,UAAU;AAC9B,WAAS,KAAK,YAAa,aAAc;AACzC,gBAAc,MAAM;AACpB,WAAS,KAAK,YAAa,aAAc;AACzC,SAAO,IAAI,gBAAiB,GAAI;AACjC;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/blob",
3
- "version": "4.32.0",
3
+ "version": "4.32.1-next.47f435fc9.0",
4
4
  "description": "Blob utilities for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -24,15 +24,20 @@
24
24
  },
25
25
  "main": "build/index.js",
26
26
  "module": "build-module/index.js",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./build-types/index.d.ts",
30
+ "import": "./build-module/index.js",
31
+ "require": "./build/index.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
27
35
  "react-native": "src/index",
28
36
  "wpScript": true,
29
37
  "types": "build-types",
30
38
  "sideEffects": false,
31
- "dependencies": {
32
- "@babel/runtime": "7.25.7"
33
- },
34
39
  "publishConfig": {
35
40
  "access": "public"
36
41
  },
37
- "gitHead": "a030b4c0e0695239b942c7dc18511782b64f10ed"
42
+ "gitHead": "9720f22c138771d2ed1a0522725c3cdf1c242953"
38
43
  }