@leapfrog/interactive-canvas 0.1.0 → 0.1.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.
|
@@ -56891,177 +56891,215 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
56891
56891
|
* @inheritDoc
|
|
56892
56892
|
*/
|
|
56893
56893
|
InteractiveCanvas.prototype.addImageObject = function (imageUrl) {
|
|
56894
|
-
|
|
56895
|
-
|
|
56896
|
-
|
|
56897
|
-
|
|
56898
|
-
|
|
56899
|
-
|
|
56900
|
-
|
|
56901
|
-
|
|
56902
|
-
|
|
56903
|
-
|
|
56904
|
-
|
|
56905
|
-
|
|
56906
|
-
|
|
56907
|
-
|
|
56908
|
-
|
|
56909
|
-
|
|
56910
|
-
|
|
56894
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56895
|
+
var maxSizeScale, maxWidth, options;
|
|
56896
|
+
var _this = this;
|
|
56897
|
+
return __generator(this, function (_a) {
|
|
56898
|
+
switch (_a.label) {
|
|
56899
|
+
case 0:
|
|
56900
|
+
maxSizeScale = 2;
|
|
56901
|
+
maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
56902
|
+
options = { crossOrigin: "anonymous" };
|
|
56903
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
56904
|
+
fabric_1.fabric.Image.fromURL(imageUrl, function (fabricImage) {
|
|
56905
|
+
var id = _this.randomId();
|
|
56906
|
+
var newScale = 1;
|
|
56907
|
+
var curWidth = newScale * fabricImage.width;
|
|
56908
|
+
if (curWidth > maxWidth) {
|
|
56909
|
+
newScale = maxWidth / curWidth;
|
|
56910
|
+
}
|
|
56911
|
+
fabricImage.set({
|
|
56912
|
+
id: id,
|
|
56913
|
+
scaleX: newScale,
|
|
56914
|
+
scaleY: newScale
|
|
56915
|
+
});
|
|
56916
|
+
_this.fabricCanvas.add(fabricImage);
|
|
56917
|
+
var object = new image_1.Image(_this, fabricImage);
|
|
56918
|
+
_this.trackNewObject(object);
|
|
56919
|
+
_this.fabricCanvas.setActiveObject(fabricImage);
|
|
56920
|
+
_this.syncObjectList();
|
|
56921
|
+
resolve(object);
|
|
56922
|
+
}, options);
|
|
56923
|
+
})];
|
|
56924
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
56925
|
+
}
|
|
56911
56926
|
});
|
|
56912
|
-
|
|
56913
|
-
var object = new image_1.Image(_this, fabricImage);
|
|
56914
|
-
_this.trackNewObject(object);
|
|
56915
|
-
_this.fabricCanvas.setActiveObject(fabricImage);
|
|
56916
|
-
_this.syncObjectList();
|
|
56917
|
-
response$.next(object);
|
|
56918
|
-
}, options);
|
|
56919
|
-
return response$;
|
|
56927
|
+
});
|
|
56920
56928
|
};
|
|
56921
56929
|
/**
|
|
56922
56930
|
* @override
|
|
56923
56931
|
* @inheritDoc
|
|
56924
56932
|
*/
|
|
56925
56933
|
InteractiveCanvas.prototype.addTextObject = function () {
|
|
56926
|
-
|
|
56927
|
-
|
|
56928
|
-
|
|
56929
|
-
|
|
56930
|
-
|
|
56931
|
-
|
|
56932
|
-
|
|
56933
|
-
|
|
56934
|
-
|
|
56935
|
-
|
|
56936
|
-
|
|
56937
|
-
|
|
56938
|
-
|
|
56939
|
-
|
|
56940
|
-
|
|
56941
|
-
|
|
56942
|
-
|
|
56943
|
-
|
|
56944
|
-
|
|
56945
|
-
|
|
56946
|
-
|
|
56947
|
-
|
|
56948
|
-
|
|
56949
|
-
|
|
56950
|
-
|
|
56951
|
-
|
|
56934
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56935
|
+
var profile, id, fontSizePx, canvasWidthPx, lowestTextPointPx, topPx, textOptions, fabricTextbox, object;
|
|
56936
|
+
return __generator(this, function (_a) {
|
|
56937
|
+
profile = this.profile$.value;
|
|
56938
|
+
id = this.randomId();
|
|
56939
|
+
fontSizePx = profile.defaultFontSize;
|
|
56940
|
+
canvasWidthPx = this.getDimensions().widthPx;
|
|
56941
|
+
lowestTextPointPx = this.getLowestTextPoint();
|
|
56942
|
+
topPx = Math.min(lowestTextPointPx, this.getDimensions().heightPx - fontSizePx);
|
|
56943
|
+
textOptions = {
|
|
56944
|
+
id: id,
|
|
56945
|
+
top: topPx,
|
|
56946
|
+
left: 5,
|
|
56947
|
+
width: canvasWidthPx - 10,
|
|
56948
|
+
fill: profile.defaultFontColor,
|
|
56949
|
+
fontSize: fontSizePx,
|
|
56950
|
+
fontFamily: profile.defaultFont,
|
|
56951
|
+
textAlign: profile.defaultTextAlignment,
|
|
56952
|
+
multiLine: true,
|
|
56953
|
+
lineHeight: profile.defaultLineHeight,
|
|
56954
|
+
charSpacing: profile.defaultCharacterSpacing
|
|
56955
|
+
};
|
|
56956
|
+
fabricTextbox = new fabric_1.fabric.Textbox("Text goes here", textOptions);
|
|
56957
|
+
this.fabricCanvas.add(fabricTextbox);
|
|
56958
|
+
object = new text_1.Text(this, fabricTextbox);
|
|
56959
|
+
this.trackNewObject(object);
|
|
56960
|
+
this.fabricCanvas.setActiveObject(fabricTextbox);
|
|
56961
|
+
this.syncObjectList();
|
|
56962
|
+
return [2 /*return*/, object];
|
|
56963
|
+
});
|
|
56964
|
+
});
|
|
56952
56965
|
};
|
|
56953
56966
|
/**
|
|
56954
56967
|
* @override
|
|
56955
56968
|
* @inheritDoc
|
|
56956
56969
|
*/
|
|
56957
56970
|
InteractiveCanvas.prototype.addRectangleObject = function () {
|
|
56958
|
-
|
|
56959
|
-
|
|
56960
|
-
|
|
56961
|
-
|
|
56962
|
-
|
|
56963
|
-
|
|
56964
|
-
|
|
56965
|
-
|
|
56966
|
-
|
|
56967
|
-
|
|
56968
|
-
|
|
56969
|
-
|
|
56970
|
-
|
|
56971
|
-
|
|
56972
|
-
|
|
56973
|
-
|
|
56974
|
-
|
|
56975
|
-
|
|
56976
|
-
|
|
56971
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56972
|
+
var canvasWidth, canvasHeight, rectWidth, rectHeight, rectangleOptions, fabricRect, object;
|
|
56973
|
+
return __generator(this, function (_a) {
|
|
56974
|
+
canvasWidth = this.getDimensions().widthPx;
|
|
56975
|
+
canvasHeight = this.getDimensions().heightPx;
|
|
56976
|
+
rectWidth = canvasWidth / 2;
|
|
56977
|
+
rectHeight = canvasHeight / 2;
|
|
56978
|
+
rectangleOptions = {
|
|
56979
|
+
id: this.randomId(),
|
|
56980
|
+
width: canvasWidth / 2,
|
|
56981
|
+
height: 2,
|
|
56982
|
+
top: canvasHeight / 2 - rectHeight / 2,
|
|
56983
|
+
left: canvasWidth / 2 - rectWidth / 2,
|
|
56984
|
+
fill: "#000000"
|
|
56985
|
+
};
|
|
56986
|
+
fabricRect = new fabric_1.fabric.Rect(rectangleOptions);
|
|
56987
|
+
this.fabricCanvas.add(fabricRect);
|
|
56988
|
+
object = new rectangle_1.Rectangle(this, fabricRect);
|
|
56989
|
+
this.trackNewObject(object);
|
|
56990
|
+
this.fabricCanvas.setActiveObject(fabricRect);
|
|
56991
|
+
this.syncObjectList();
|
|
56992
|
+
return [2 /*return*/, object];
|
|
56993
|
+
});
|
|
56994
|
+
});
|
|
56977
56995
|
};
|
|
56978
56996
|
/**
|
|
56979
56997
|
* @override
|
|
56980
56998
|
* @inheritDoc
|
|
56981
56999
|
*/
|
|
56982
57000
|
InteractiveCanvas.prototype.addCutoffObject = function () {
|
|
56983
|
-
|
|
56984
|
-
|
|
56985
|
-
|
|
56986
|
-
|
|
56987
|
-
|
|
56988
|
-
|
|
56989
|
-
|
|
56990
|
-
|
|
56991
|
-
|
|
56992
|
-
|
|
56993
|
-
|
|
56994
|
-
|
|
56995
|
-
|
|
56996
|
-
|
|
56997
|
-
|
|
56998
|
-
|
|
56999
|
-
|
|
57000
|
-
|
|
57001
|
-
|
|
57001
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57002
|
+
var profile, initialThickness, canvasWidth, canvasHeight, rectangleOptions, fabricRect, object;
|
|
57003
|
+
return __generator(this, function (_a) {
|
|
57004
|
+
profile = this.profile$.value;
|
|
57005
|
+
initialThickness = profile.defaultCutoffWidth;
|
|
57006
|
+
canvasWidth = this.getDimensions().widthPx;
|
|
57007
|
+
canvasHeight = this.getDimensions().heightPx;
|
|
57008
|
+
rectangleOptions = {
|
|
57009
|
+
id: this.randomId(),
|
|
57010
|
+
width: canvasWidth,
|
|
57011
|
+
height: initialThickness,
|
|
57012
|
+
top: canvasHeight - initialThickness,
|
|
57013
|
+
left: 0,
|
|
57014
|
+
fill: profile.defaultCutoffColor
|
|
57015
|
+
};
|
|
57016
|
+
fabricRect = new fabric_1.fabric.Rect(rectangleOptions);
|
|
57017
|
+
this.fabricCanvas.add(fabricRect);
|
|
57018
|
+
object = new cutoff_1.Cutoff(this, fabricRect);
|
|
57019
|
+
this.trackNewObject(object);
|
|
57020
|
+
this.fabricCanvas.setActiveObject(fabricRect);
|
|
57021
|
+
this.syncObjectList();
|
|
57022
|
+
return [2 /*return*/, object];
|
|
57023
|
+
});
|
|
57024
|
+
});
|
|
57002
57025
|
};
|
|
57003
57026
|
/**
|
|
57004
57027
|
* @override
|
|
57005
57028
|
* @inheritDoc
|
|
57006
57029
|
*/
|
|
57007
57030
|
InteractiveCanvas.prototype.addBorderObject = function () {
|
|
57008
|
-
|
|
57009
|
-
|
|
57010
|
-
|
|
57011
|
-
|
|
57012
|
-
|
|
57013
|
-
|
|
57014
|
-
|
|
57015
|
-
|
|
57016
|
-
|
|
57017
|
-
|
|
57018
|
-
|
|
57019
|
-
|
|
57020
|
-
|
|
57021
|
-
|
|
57022
|
-
|
|
57031
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57032
|
+
var profile, initialThickness, rectangleOptions, fabricRect, object;
|
|
57033
|
+
return __generator(this, function (_a) {
|
|
57034
|
+
profile = this.profile$.value;
|
|
57035
|
+
initialThickness = profile.defaultBorderWidth;
|
|
57036
|
+
rectangleOptions = {
|
|
57037
|
+
id: this.randomId(),
|
|
57038
|
+
fill: null,
|
|
57039
|
+
stroke: profile.defaultBorderColor,
|
|
57040
|
+
strokeWidth: initialThickness
|
|
57041
|
+
};
|
|
57042
|
+
fabricRect = new fabric_1.fabric.Rect(rectangleOptions);
|
|
57043
|
+
this.fabricCanvas.add(fabricRect);
|
|
57044
|
+
object = new border_1.Border(this, fabricRect);
|
|
57045
|
+
this.trackNewObject(object);
|
|
57046
|
+
this.fabricCanvas.setActiveObject(fabricRect);
|
|
57047
|
+
this.syncObjectList();
|
|
57048
|
+
return [2 /*return*/, object];
|
|
57049
|
+
});
|
|
57050
|
+
});
|
|
57023
57051
|
};
|
|
57024
57052
|
/**
|
|
57025
57053
|
* @override
|
|
57026
57054
|
* @inheritDoc
|
|
57027
57055
|
*/
|
|
57028
57056
|
InteractiveCanvas.prototype.addVerticalRuleObject = function () {
|
|
57029
|
-
|
|
57030
|
-
|
|
57031
|
-
|
|
57032
|
-
|
|
57033
|
-
|
|
57034
|
-
|
|
57035
|
-
|
|
57036
|
-
|
|
57037
|
-
|
|
57038
|
-
|
|
57039
|
-
|
|
57040
|
-
|
|
57041
|
-
|
|
57042
|
-
|
|
57043
|
-
|
|
57057
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57058
|
+
var rectOptions, fabricRect, object;
|
|
57059
|
+
return __generator(this, function (_a) {
|
|
57060
|
+
rectOptions = {
|
|
57061
|
+
id: this.randomId(),
|
|
57062
|
+
width: 2,
|
|
57063
|
+
height: 10,
|
|
57064
|
+
top: 0,
|
|
57065
|
+
left: 0,
|
|
57066
|
+
fill: "#000000"
|
|
57067
|
+
};
|
|
57068
|
+
fabricRect = new fabric_1.fabric.Rect(rectOptions);
|
|
57069
|
+
this.fabricCanvas.add(fabricRect);
|
|
57070
|
+
object = new vertical_rule_1.VerticalRule(this, fabricRect);
|
|
57071
|
+
this.trackNewObject(object);
|
|
57072
|
+
this.fabricCanvas.setActiveObject(fabricRect);
|
|
57073
|
+
this.syncObjectList();
|
|
57074
|
+
return [2 /*return*/, object];
|
|
57075
|
+
});
|
|
57076
|
+
});
|
|
57044
57077
|
};
|
|
57045
57078
|
/**
|
|
57046
57079
|
* @override
|
|
57047
57080
|
* @inheritDoc
|
|
57048
57081
|
*/
|
|
57049
57082
|
InteractiveCanvas.prototype.addHorizontalRuleObject = function () {
|
|
57050
|
-
|
|
57051
|
-
|
|
57052
|
-
|
|
57053
|
-
|
|
57054
|
-
|
|
57055
|
-
|
|
57056
|
-
|
|
57057
|
-
|
|
57058
|
-
|
|
57059
|
-
|
|
57060
|
-
|
|
57061
|
-
|
|
57062
|
-
|
|
57063
|
-
|
|
57064
|
-
|
|
57083
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57084
|
+
var rectOptions, fabricRect, object;
|
|
57085
|
+
return __generator(this, function (_a) {
|
|
57086
|
+
rectOptions = {
|
|
57087
|
+
id: this.randomId(),
|
|
57088
|
+
width: 10,
|
|
57089
|
+
height: 2,
|
|
57090
|
+
top: 0,
|
|
57091
|
+
left: 0,
|
|
57092
|
+
fill: "#000000"
|
|
57093
|
+
};
|
|
57094
|
+
fabricRect = new fabric_1.fabric.Rect(rectOptions);
|
|
57095
|
+
this.fabricCanvas.add(fabricRect);
|
|
57096
|
+
object = new horizontal_rule_1.HorizontalRule(this, fabricRect);
|
|
57097
|
+
this.trackNewObject(object);
|
|
57098
|
+
this.fabricCanvas.setActiveObject(fabricRect);
|
|
57099
|
+
this.syncObjectList();
|
|
57100
|
+
return [2 /*return*/, object];
|
|
57101
|
+
});
|
|
57102
|
+
});
|
|
57065
57103
|
};
|
|
57066
57104
|
/**
|
|
57067
57105
|
* @override
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -21,7 +21,7 @@ Add the following lines to the `package.json` `scripts` config in the project th
|
|
|
21
21
|
{
|
|
22
22
|
"scripts": {
|
|
23
23
|
"link:lic": "npm link @leapfrog/interactive-canvas",
|
|
24
|
-
"upgrade:lic": "npm install @leapfrog/interactive-canvas@latest"
|
|
24
|
+
"upgrade:lic": "npm install @leapfrog/interactive-canvas@latest --save"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
```
|