@leapfrog/interactive-canvas 1.4.3 → 1.5.1

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.
@@ -485,7 +485,8 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
485
485
  if (oc(canvas.getDimensionsRestrictions()).fixed(false))
486
486
  return;
487
487
  var dimensions = canvas.getDimensions();
488
- var targetDimensions = canvas.getDimensions().withSize(dimensions.width, MIN_MAGNITUDE);
488
+ var minHeight = oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
489
+ var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
489
490
  while (targetDimensions.heightPx < requiredHeight) {
490
491
  targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
491
492
  }
@@ -1433,10 +1434,19 @@ var Image = /** @class */ (function (_super) {
1433
1434
  * @inheritDoc
1434
1435
  */
1435
1436
  Image.prototype.setImageUrl = function (url) {
1436
- this.setCanvasImage(url);
1437
- this.data.imagePath = url;
1438
- this.imageUrl$.next(url);
1439
- this.canvas.notifyObjectListChanged();
1437
+ return __awaiter(this, void 0, void 0, function () {
1438
+ return __generator(this, function (_a) {
1439
+ switch (_a.label) {
1440
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1441
+ case 1:
1442
+ _a.sent();
1443
+ this.data.imagePath = url;
1444
+ this.imageUrl$.next(url);
1445
+ this.canvas.notifyObjectListChanged();
1446
+ return [2 /*return*/];
1447
+ }
1448
+ });
1449
+ });
1440
1450
  };
1441
1451
  /**
1442
1452
  * @override
@@ -1531,24 +1541,35 @@ var Image = /** @class */ (function (_super) {
1531
1541
  this.fabricObject.set({ left: left + (this.layoutWidth / 2) - (imageWidth / 2) });
1532
1542
  };
1533
1543
  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
1544
+ return __awaiter(this, void 0, void 0, function () {
1545
+ var imageOptions, maxSizeScale, maxWidth;
1546
+ var _this = this;
1547
+ return __generator(this, function (_a) {
1548
+ switch (_a.label) {
1549
+ case 0:
1550
+ imageOptions = { crossOrigin: "anonymous" };
1551
+ maxSizeScale = 2;
1552
+ maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1553
+ return [4 /*yield*/, new Promise(function (resolve) {
1554
+ _this.fabricObject.setSrc(url, function (img) {
1555
+ var newScale = 1;
1556
+ var curWidth = newScale * img.width;
1557
+ if (curWidth > maxWidth) {
1558
+ newScale = maxWidth / curWidth;
1559
+ }
1560
+ img.set({
1561
+ scaleX: newScale,
1562
+ scaleY: newScale
1563
+ });
1564
+ img.setCoords();
1565
+ _this.redraw();
1566
+ resolve();
1567
+ }, imageOptions);
1568
+ })];
1569
+ case 1: return [2 /*return*/, _a.sent()];
1570
+ }
1548
1571
  });
1549
- img.setCoords();
1550
- _this.redraw();
1551
- }, imageOptions);
1572
+ });
1552
1573
  };
1553
1574
  Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
1554
1575
  if (!minHeight) {
@@ -487,7 +487,8 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
487
487
  if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
488
488
  return;
489
489
  var dimensions = canvas.getDimensions();
490
- var targetDimensions = canvas.getDimensions().withSize(dimensions.width, MIN_MAGNITUDE);
490
+ var minHeight = tsOptchain.oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
491
+ var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
491
492
  while (targetDimensions.heightPx < requiredHeight) {
492
493
  targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
493
494
  }
@@ -1435,10 +1436,19 @@ var Image = /** @class */ (function (_super) {
1435
1436
  * @inheritDoc
1436
1437
  */
1437
1438
  Image.prototype.setImageUrl = function (url) {
1438
- this.setCanvasImage(url);
1439
- this.data.imagePath = url;
1440
- this.imageUrl$.next(url);
1441
- this.canvas.notifyObjectListChanged();
1439
+ return __awaiter(this, void 0, void 0, function () {
1440
+ return __generator(this, function (_a) {
1441
+ switch (_a.label) {
1442
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1443
+ case 1:
1444
+ _a.sent();
1445
+ this.data.imagePath = url;
1446
+ this.imageUrl$.next(url);
1447
+ this.canvas.notifyObjectListChanged();
1448
+ return [2 /*return*/];
1449
+ }
1450
+ });
1451
+ });
1442
1452
  };
1443
1453
  /**
1444
1454
  * @override
@@ -1533,24 +1543,35 @@ var Image = /** @class */ (function (_super) {
1533
1543
  this.fabricObject.set({ left: left + (this.layoutWidth / 2) - (imageWidth / 2) });
1534
1544
  };
1535
1545
  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
1546
+ return __awaiter(this, void 0, void 0, function () {
1547
+ var imageOptions, maxSizeScale, maxWidth;
1548
+ var _this = this;
1549
+ return __generator(this, function (_a) {
1550
+ switch (_a.label) {
1551
+ case 0:
1552
+ imageOptions = { crossOrigin: "anonymous" };
1553
+ maxSizeScale = 2;
1554
+ maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1555
+ return [4 /*yield*/, new Promise(function (resolve) {
1556
+ _this.fabricObject.setSrc(url, function (img) {
1557
+ var newScale = 1;
1558
+ var curWidth = newScale * img.width;
1559
+ if (curWidth > maxWidth) {
1560
+ newScale = maxWidth / curWidth;
1561
+ }
1562
+ img.set({
1563
+ scaleX: newScale,
1564
+ scaleY: newScale
1565
+ });
1566
+ img.setCoords();
1567
+ _this.redraw();
1568
+ resolve();
1569
+ }, imageOptions);
1570
+ })];
1571
+ case 1: return [2 /*return*/, _a.sent()];
1572
+ }
1550
1573
  });
1551
- img.setCoords();
1552
- _this.redraw();
1553
- }, imageOptions);
1574
+ });
1554
1575
  };
1555
1576
  Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
1556
1577
  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.1",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"