@@ -6268,19 +6268,9 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
6268
6268
const img = this . _getImg ( ) ;
6269
6269
const _super = this . _super . bind ( this ) ;
6270
6270
6271
- // Make sure image is loaded because we need its naturalWidth
6272
- await new Promise ( ( resolve , reject ) => {
6273
- if ( img . complete ) {
6274
- resolve ( ) ;
6275
- return ;
6276
- }
6277
- img . addEventListener ( 'load' , resolve , { once : true } ) ;
6278
- img . addEventListener ( 'error' , resolve , { once : true } ) ;
6279
- } ) ;
6280
-
6281
6271
switch ( methodName ) {
6282
6272
case 'selectFormat' :
6283
- return this . _getCurrentFormat ( img ) ;
6273
+ return await this . _getCurrentFormat ( img ) ;
6284
6274
case 'setFilter' :
6285
6275
return img . dataset . filter ;
6286
6276
case 'glFilter' :
@@ -6373,7 +6363,7 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
6373
6363
// - Changing the specs of the available formats, where some previously
6374
6364
// used format cannot be selected anymore
6375
6365
// - External modification of the format
6376
- const currentFormat = this . _getCurrentFormat ( img ) ;
6366
+ const currentFormat = await this . _getCurrentFormat ( img ) ;
6377
6367
const [ selectedSize , selectedMimetype ] = currentFormat ?. split ( " " ) || [ ] ;
6378
6368
if (
6379
6369
selectedSize &&
@@ -6552,12 +6542,12 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
6552
6542
} ,
6553
6543
/**
6554
6544
* @param {HTMLImageElement } [image] Override image element.
6555
- * @return {string } The image's current width.
6545
+ * @return {Promise< string> } The image's current width (selected format) .
6556
6546
* @private
6557
6547
*/
6558
- _getImageWidth ( image = this . _getImg ( ) ) {
6548
+ async _getImageWidth ( image = this . _getImg ( ) ) {
6559
6549
return Math . trunc (
6560
- image . dataset . resizeWidth || image . dataset . width || image . naturalWidth
6550
+ image . dataset . resizeWidth || image . dataset . width || ( await this . _getOriginalSize ( ) )
6561
6551
) . toString ( ) ;
6562
6552
} ,
6563
6553
/**
@@ -6571,11 +6561,11 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
6571
6561
} ,
6572
6562
/**
6573
6563
* @param {HTMLImageElement } img
6574
- * @return {string } The image's current format (widget value).
6564
+ * @return {Promise< string> } The image's current format (widget value).
6575
6565
* @private
6576
6566
*/
6577
- _getCurrentFormat ( img ) {
6578
- return `${ img . naturalWidth } ${ this . _getImageMimetype ( img ) } ` ;
6567
+ async _getCurrentFormat ( img ) {
6568
+ return `${ await this . _getImageWidth ( img ) } ${ this . _getImageMimetype ( img ) } ` ;
6579
6569
} ,
6580
6570
/**
6581
6571
* Returns whether the format is the image's original format.
@@ -6604,7 +6594,7 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
6604
6594
* @private
6605
6595
*/
6606
6596
async _getImageTargetMimetype ( image = this . _getImg ( ) ) {
6607
- const currentSize = this . _getImageWidth ( image ) ;
6597
+ const currentSize = await this . _getImageWidth ( image ) ;
6608
6598
const currentMimetype = this . _getImageMimetype ( image ) ;
6609
6599
6610
6600
const isOriginalFormat = await this . _isOriginalFormat ( currentSize , currentMimetype ) ;
0 commit comments