@leapfrog/interactive-canvas 1.4.3 → 1.5.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.
@@ -1433,10 +1433,19 @@ var Image = /** @class */ (function (_super) {
1433
1433
  * @inheritDoc
1434
1434
  */
1435
1435
  Image.prototype.setImageUrl = function (url) {
1436
- this.setCanvasImage(url);
1437
- this.data.imagePath = url;
1438
- this.imageUrl$.next(url);
1439
- this.canvas.notifyObjectListChanged();
1436
+ return __awaiter(this, void 0, void 0, function () {
1437
+ return __generator(this, function (_a) {
1438
+ switch (_a.label) {
1439
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1440
+ case 1:
1441
+ _a.sent();
1442
+ this.data.imagePath = url;
1443
+ this.imageUrl$.next(url);
1444
+ this.canvas.notifyObjectListChanged();
1445
+ return [2 /*return*/];
1446
+ }
1447
+ });
1448
+ });
1440
1449
  };
1441
1450
  /**
1442
1451
  * @override
@@ -1531,24 +1540,35 @@ var Image = /** @class */ (function (_super) {
1531
1540
  this.fabricObject.set({ left: left + (this.layoutWidth / 2) - (imageWidth / 2) });
1532
1541
  };
1533
1542
  Image.prototype.setCanvasImage = function (url) {
1534
- var _this = this;
1535
- var imageOptions = { crossOrigin: "anonymous" };
1536
- //Don't let the image be more than half the canvas in size.
1537
- var maxSizeScale = 2;
1538
- var maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1539
- this.fabricObject.setSrc(url, function (img) {
1540
- var newScale = 1;
1541
- var curWidth = newScale * img.width;
1542
- if (curWidth > maxWidth) {
1543
- newScale = maxWidth / curWidth;
1544
- }
1545
- img.set({
1546
- scaleX: newScale,
1547
- scaleY: newScale
1543
+ return __awaiter(this, void 0, void 0, function () {
1544
+ var imageOptions, maxSizeScale, maxWidth;
1545
+ var _this = this;
1546
+ return __generator(this, function (_a) {
1547
+ switch (_a.label) {
1548
+ case 0:
1549
+ imageOptions = { crossOrigin: "anonymous" };
1550
+ maxSizeScale = 2;
1551
+ maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1552
+ return [4 /*yield*/, new Promise(function (resolve) {
1553
+ _this.fabricObject.setSrc(url, function (img) {
1554
+ var newScale = 1;
1555
+ var curWidth = newScale * img.width;
1556
+ if (curWidth > maxWidth) {
1557
+ newScale = maxWidth / curWidth;
1558
+ }
1559
+ img.set({
1560
+ scaleX: newScale,
1561
+ scaleY: newScale
1562
+ });
1563
+ img.setCoords();
1564
+ _this.redraw();
1565
+ resolve();
1566
+ }, imageOptions);
1567
+ })];
1568
+ case 1: return [2 /*return*/, _a.sent()];
1569
+ }
1548
1570
  });
1549
- img.setCoords();
1550
- _this.redraw();
1551
- }, imageOptions);
1571
+ });
1552
1572
  };
1553
1573
  Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
1554
1574
  if (!minHeight) {
@@ -1435,10 +1435,19 @@ var Image = /** @class */ (function (_super) {
1435
1435
  * @inheritDoc
1436
1436
  */
1437
1437
  Image.prototype.setImageUrl = function (url) {
1438
- this.setCanvasImage(url);
1439
- this.data.imagePath = url;
1440
- this.imageUrl$.next(url);
1441
- this.canvas.notifyObjectListChanged();
1438
+ return __awaiter(this, void 0, void 0, function () {
1439
+ return __generator(this, function (_a) {
1440
+ switch (_a.label) {
1441
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1442
+ case 1:
1443
+ _a.sent();
1444
+ this.data.imagePath = url;
1445
+ this.imageUrl$.next(url);
1446
+ this.canvas.notifyObjectListChanged();
1447
+ return [2 /*return*/];
1448
+ }
1449
+ });
1450
+ });
1442
1451
  };
1443
1452
  /**
1444
1453
  * @override
@@ -1533,24 +1542,35 @@ var Image = /** @class */ (function (_super) {
1533
1542
  this.fabricObject.set({ left: left + (this.layoutWidth / 2) - (imageWidth / 2) });
1534
1543
  };
1535
1544
  Image.prototype.setCanvasImage = function (url) {
1536
- var _this = this;
1537
- var imageOptions = { crossOrigin: "anonymous" };
1538
- //Don't let the image be more than half the canvas in size.
1539
- var maxSizeScale = 2;
1540
- var maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1541
- this.fabricObject.setSrc(url, function (img) {
1542
- var newScale = 1;
1543
- var curWidth = newScale * img.width;
1544
- if (curWidth > maxWidth) {
1545
- newScale = maxWidth / curWidth;
1546
- }
1547
- img.set({
1548
- scaleX: newScale,
1549
- scaleY: newScale
1545
+ return __awaiter(this, void 0, void 0, function () {
1546
+ var imageOptions, maxSizeScale, maxWidth;
1547
+ var _this = this;
1548
+ return __generator(this, function (_a) {
1549
+ switch (_a.label) {
1550
+ case 0:
1551
+ imageOptions = { crossOrigin: "anonymous" };
1552
+ maxSizeScale = 2;
1553
+ maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1554
+ return [4 /*yield*/, new Promise(function (resolve) {
1555
+ _this.fabricObject.setSrc(url, function (img) {
1556
+ var newScale = 1;
1557
+ var curWidth = newScale * img.width;
1558
+ if (curWidth > maxWidth) {
1559
+ newScale = maxWidth / curWidth;
1560
+ }
1561
+ img.set({
1562
+ scaleX: newScale,
1563
+ scaleY: newScale
1564
+ });
1565
+ img.setCoords();
1566
+ _this.redraw();
1567
+ resolve();
1568
+ }, imageOptions);
1569
+ })];
1570
+ case 1: return [2 /*return*/, _a.sent()];
1571
+ }
1550
1572
  });
1551
- img.setCoords();
1552
- _this.redraw();
1553
- }, imageOptions);
1573
+ });
1554
1574
  };
1555
1575
  Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
1556
1576
  if (!minHeight) {
@@ -16,7 +16,7 @@ export interface IMutableImage extends ICanvasObject {
16
16
  * Set the image url.
17
17
  * @param url New url.
18
18
  */
19
- setImageUrl(url: string): void;
19
+ setImageUrl(url: string): Promise<void>;
20
20
  /**
21
21
  * Sets the image width to x pixels.
22
22
  * @param px Pixels.
@@ -28,7 +28,7 @@ export declare class Image extends AbstractCanvasObject<fabric.Image> implements
28
28
  * @override
29
29
  * @inheritDoc
30
30
  */
31
- setImageUrl(url: string): void;
31
+ setImageUrl(url: string): Promise<void>;
32
32
  /**
33
33
  * @override
34
34
  * @inheritDoc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"