@leapfrog/interactive-canvas 1.4.2 → 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.
@@ -564,6 +564,13 @@ var StandardLayoutManager = /** @class */ (function (_super) {
564
564
  this.canvas.setMultiSelect(false);
565
565
  this.redrawAll.execute(this.canvas);
566
566
  };
567
+ /**
568
+ * @override
569
+ */
570
+ StandardLayoutManager.prototype.onCanvasDimensionsChange = function () {
571
+ this.repositionCutoffs.execute(this.canvas);
572
+ this.repositionBorders.execute(this.canvas);
573
+ };
567
574
  /**
568
575
  * @override
569
576
  */
@@ -1426,10 +1433,19 @@ var Image = /** @class */ (function (_super) {
1426
1433
  * @inheritDoc
1427
1434
  */
1428
1435
  Image.prototype.setImageUrl = function (url) {
1429
- this.setCanvasImage(url);
1430
- this.data.imagePath = url;
1431
- this.imageUrl$.next(url);
1432
- 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
+ });
1433
1449
  };
1434
1450
  /**
1435
1451
  * @override
@@ -1524,24 +1540,35 @@ var Image = /** @class */ (function (_super) {
1524
1540
  this.fabricObject.set({ left: left + (this.layoutWidth / 2) - (imageWidth / 2) });
1525
1541
  };
1526
1542
  Image.prototype.setCanvasImage = function (url) {
1527
- var _this = this;
1528
- var imageOptions = { crossOrigin: "anonymous" };
1529
- //Don't let the image be more than half the canvas in size.
1530
- var maxSizeScale = 2;
1531
- var maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1532
- this.fabricObject.setSrc(url, function (img) {
1533
- var newScale = 1;
1534
- var curWidth = newScale * img.width;
1535
- if (curWidth > maxWidth) {
1536
- newScale = maxWidth / curWidth;
1537
- }
1538
- img.set({
1539
- scaleX: newScale,
1540
- 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
+ }
1541
1570
  });
1542
- img.setCoords();
1543
- _this.redraw();
1544
- }, imageOptions);
1571
+ });
1545
1572
  };
1546
1573
  Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
1547
1574
  if (!minHeight) {
@@ -566,6 +566,13 @@ var StandardLayoutManager = /** @class */ (function (_super) {
566
566
  this.canvas.setMultiSelect(false);
567
567
  this.redrawAll.execute(this.canvas);
568
568
  };
569
+ /**
570
+ * @override
571
+ */
572
+ StandardLayoutManager.prototype.onCanvasDimensionsChange = function () {
573
+ this.repositionCutoffs.execute(this.canvas);
574
+ this.repositionBorders.execute(this.canvas);
575
+ };
569
576
  /**
570
577
  * @override
571
578
  */
@@ -1428,10 +1435,19 @@ var Image = /** @class */ (function (_super) {
1428
1435
  * @inheritDoc
1429
1436
  */
1430
1437
  Image.prototype.setImageUrl = function (url) {
1431
- this.setCanvasImage(url);
1432
- this.data.imagePath = url;
1433
- this.imageUrl$.next(url);
1434
- 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
+ });
1435
1451
  };
1436
1452
  /**
1437
1453
  * @override
@@ -1526,24 +1542,35 @@ var Image = /** @class */ (function (_super) {
1526
1542
  this.fabricObject.set({ left: left + (this.layoutWidth / 2) - (imageWidth / 2) });
1527
1543
  };
1528
1544
  Image.prototype.setCanvasImage = function (url) {
1529
- var _this = this;
1530
- var imageOptions = { crossOrigin: "anonymous" };
1531
- //Don't let the image be more than half the canvas in size.
1532
- var maxSizeScale = 2;
1533
- var maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1534
- this.fabricObject.setSrc(url, function (img) {
1535
- var newScale = 1;
1536
- var curWidth = newScale * img.width;
1537
- if (curWidth > maxWidth) {
1538
- newScale = maxWidth / curWidth;
1539
- }
1540
- img.set({
1541
- scaleX: newScale,
1542
- 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
+ }
1543
1572
  });
1544
- img.setCoords();
1545
- _this.redraw();
1546
- }, imageOptions);
1573
+ });
1547
1574
  };
1548
1575
  Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
1549
1576
  if (!minHeight) {
@@ -19,6 +19,10 @@ export declare class StandardLayoutManager extends AbstractLayoutManager {
19
19
  * @override
20
20
  */
21
21
  onProfileChange(profile: ICanvasProfile): void;
22
+ /**
23
+ * @override
24
+ */
25
+ onCanvasDimensionsChange(): void;
22
26
  /**
23
27
  * @override
24
28
  */
@@ -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.2",
3
+ "version": "1.5.0",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"