@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
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
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
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
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
|
-
|
|
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
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
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
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
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
|
-
|
|
1552
|
-
_this.redraw();
|
|
1553
|
-
}, imageOptions);
|
|
1573
|
+
});
|
|
1554
1574
|
};
|
|
1555
1575
|
Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
|
|
1556
1576
|
if (!minHeight) {
|