|
|
@@ -10,7 +10,7 @@
|
|
|
/* global fetch, File */
|
|
|
|
|
|
/**
|
|
|
- * Creates a RegExp used to test for image files.
|
|
|
+ * Creates a regular expression used to test for image files.
|
|
|
*
|
|
|
* const imageType = createImageTypeRegExp( [ 'png', 'jpeg', 'svg+xml', 'vnd.microsoft.icon' ] );
|
|
|
*
|
|
|
@@ -20,18 +20,18 @@
|
|
|
* @returns {RegExp}
|
|
|
*/
|
|
|
export function createImageTypeRegExp( types ) {
|
|
|
- // Sanitize mime-type name which may include: "+", "-" or ".".
|
|
|
+ // Sanitize the MIME type name which may include: "+", "-" or ".".
|
|
|
const regExpSafeNames = types.map( type => type.replace( '+', '\\+' ) );
|
|
|
|
|
|
return new RegExp( `^image\\/(${ regExpSafeNames.join( '|' ) })$` );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Creates a promise which fetches the image local source (base64 or blob) and resolves with a `File` object.
|
|
|
+ * Creates a promise that fetches the image local source (Base64 or blob) and resolves with a `File` object.
|
|
|
*
|
|
|
- * @param {module:engine/view/element~Element} image Image which source to fetch.
|
|
|
- * @returns {Promise.<File>} A promise which resolves when image source is fetched and converted to `File` instance.
|
|
|
- * It resolves with a `File` object. If there were any errors during file processing the promise will be rejected.
|
|
|
+ * @param {module:engine/view/element~Element} image Image whose source to fetch.
|
|
|
+ * @returns {Promise.<File>} A promise which resolves when an image source is fetched and converted to a `File` instance.
|
|
|
+ * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
|
|
|
*/
|
|
|
export function fetchLocalImage( image ) {
|
|
|
return new Promise( ( resolve, reject ) => {
|
|
|
@@ -53,9 +53,9 @@ export function fetchLocalImage( image ) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Checks whether given node is an image element with local source (base64 or blob).
|
|
|
+ * Checks whether a given node is an image element with a local source (Base64 or blob).
|
|
|
*
|
|
|
- * @param {module:engine/view/node~Node} node Node to check.
|
|
|
+ * @param {module:engine/view/node~Node} node The node to check.
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function isLocalImage( node ) {
|
|
|
@@ -67,9 +67,9 @@ export function isLocalImage( node ) {
|
|
|
node.getAttribute( 'src' ).match( /^blob:/g );
|
|
|
}
|
|
|
|
|
|
-// Extracts image type based on its blob representation or its source.
|
|
|
+// Extracts an image type based on its blob representation or its source.
|
|
|
//
|
|
|
-// @param {String} src Image src attribute value.
|
|
|
+// @param {String} src Image `src` attribute value.
|
|
|
// @param {Blob} blob Image blob representation.
|
|
|
// @returns {String}
|
|
|
function getImageMimeType( blob, src ) {
|
|
|
@@ -83,11 +83,11 @@ function getImageMimeType( blob, src ) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// Creates `File` instance from the given `Blob` instance using specified filename.
|
|
|
+// Creates a `File` instance from the given `Blob` instance using the specified file name.
|
|
|
//
|
|
|
-// @param {Blob} blob The `Blob` instance from which file will be created.
|
|
|
-// @param {String} filename Filename used during file creation.
|
|
|
-// @param {String} mimeType File mime type.
|
|
|
+// @param {Blob} blob The `Blob` instance from which the file will be created.
|
|
|
+// @param {String} filename The file name used during the file creation.
|
|
|
+// @param {String} mimeType The file MIME type.
|
|
|
// @returns {File|null} The `File` instance created from the given blob or `null` if `File API` is not available.
|
|
|
function createFileFromBlob( blob, filename, mimeType ) {
|
|
|
try {
|