@pacem/pacem-foundation 2.0.0-abel → 2.0.0-babbage

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-foundation v2.0.0-abel (https://js.pacem.it)
2
+ * @pacem/pacem-foundation v2.0.0-babbage (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -1425,11 +1425,8 @@
1425
1425
  if (width <= 0 || height <= 0 || isNaN(width) || isNaN(height)) {
1426
1426
  throw new Error('Invalid target size');
1427
1427
  }
1428
- if (typeof img === 'string') {
1429
- img = await Imaging.loadImage(img);
1430
- }
1431
- const el = await self.createImageBitmap(img);
1432
- const origWidth = el.width, origHeight = el.height;
1428
+ const el = await Imaging._toDrawable(img);
1429
+ const origWidth = el.width || width, origHeight = el.height || height;
1433
1430
  const cnv = new OffscreenCanvas(origWidth, origHeight);
1434
1431
  const ctx = cnv.getContext('2d');
1435
1432
  ctx.imageSmoothingEnabled =
@@ -1451,6 +1448,16 @@
1451
1448
  const retval = await cnv.convertToBlob({ quality, type });
1452
1449
  return retval;
1453
1450
  }
1451
+ /** Turns a URL or a `Blob` into a drawable source, while passing an already drawable source through untouched. */
1452
+ static async _toDrawable(img) {
1453
+ if (typeof img === 'string') {
1454
+ img = await Imaging.loadImage(img);
1455
+ }
1456
+ if (!(img instanceof Blob)) {
1457
+ return img;
1458
+ }
1459
+ return await self.createImageBitmap(img);
1460
+ }
1454
1461
  }
1455
1462
  // }
1456
1463