@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
- var _this = this;
56895
- var response$ = new rxjs_1.ReplaySubject(1);
56896
- //Don't let the image be more than half the canvas in size.
56897
- var maxSizeScale = 2;
56898
- var maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
56899
- var options = { crossOrigin: "anonymous" };
56900
- fabric_1.fabric.Image.fromURL(imageUrl, function (fabricImage) {
56901
- var id = _this.randomId();
56902
- var newScale = 1;
56903
- var curWidth = newScale * fabricImage.width;
56904
- if (curWidth > maxWidth) {
56905
- newScale = maxWidth / curWidth;
56906
- }
56907
- fabricImage.set({
56908
- id: id,
56909
- scaleX: newScale,
56910
- scaleY: newScale
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
- _this.fabricCanvas.add(fabricImage);
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
- var profile = this.profile$.value;
56927
- var id = this.randomId();
56928
- var fontSizePx = profile.defaultFontSize;
56929
- var canvasWidthPx = this.getDimensions().widthPx;
56930
- var lowestTextPointPx = this.getLowestTextPoint();
56931
- var topPx = Math.min(lowestTextPointPx, this.getDimensions().heightPx - fontSizePx);
56932
- var textOptions = {
56933
- id: id,
56934
- top: topPx,
56935
- left: 5,
56936
- width: canvasWidthPx - 10,
56937
- fill: profile.defaultFontColor,
56938
- fontSize: fontSizePx,
56939
- fontFamily: profile.defaultFont,
56940
- textAlign: profile.defaultTextAlignment,
56941
- multiLine: true,
56942
- lineHeight: profile.defaultLineHeight,
56943
- charSpacing: profile.defaultCharacterSpacing
56944
- };
56945
- var fabricTextbox = new fabric_1.fabric.Textbox("Text goes here", textOptions);
56946
- this.fabricCanvas.add(fabricTextbox);
56947
- var object = new text_1.Text(this, fabricTextbox);
56948
- this.trackNewObject(object);
56949
- this.fabricCanvas.setActiveObject(fabricTextbox);
56950
- this.syncObjectList();
56951
- return new rxjs_1.BehaviorSubject(object);
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
- var canvasWidth = this.getDimensions().widthPx;
56959
- var canvasHeight = this.getDimensions().heightPx;
56960
- var rectWidth = canvasWidth / 2;
56961
- var rectHeight = canvasHeight / 2;
56962
- var rectangleOptions = {
56963
- id: this.randomId(),
56964
- width: canvasWidth / 2,
56965
- height: 2,
56966
- top: canvasHeight / 2 - rectHeight / 2,
56967
- left: canvasWidth / 2 - rectWidth / 2,
56968
- fill: "#000000"
56969
- };
56970
- var fabricRect = new fabric_1.fabric.Rect(rectangleOptions);
56971
- this.fabricCanvas.add(fabricRect);
56972
- var object = new rectangle_1.Rectangle(this, fabricRect);
56973
- this.trackNewObject(object);
56974
- this.fabricCanvas.setActiveObject(fabricRect);
56975
- this.syncObjectList();
56976
- return new rxjs_1.BehaviorSubject(object);
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
- var profile = this.profile$.value;
56984
- var initialThickness = profile.defaultCutoffWidth;
56985
- var canvasWidth = this.getDimensions().widthPx;
56986
- var canvasHeight = this.getDimensions().heightPx;
56987
- var rectangleOptions = {
56988
- id: this.randomId(),
56989
- width: canvasWidth,
56990
- height: initialThickness,
56991
- top: canvasHeight - initialThickness,
56992
- left: 0,
56993
- fill: profile.defaultCutoffColor
56994
- };
56995
- var fabricRect = new fabric_1.fabric.Rect(rectangleOptions);
56996
- this.fabricCanvas.add(fabricRect);
56997
- var object = new cutoff_1.Cutoff(this, fabricRect);
56998
- this.trackNewObject(object);
56999
- this.fabricCanvas.setActiveObject(fabricRect);
57000
- this.syncObjectList();
57001
- return new rxjs_1.BehaviorSubject(object);
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
- var profile = this.profile$.value;
57009
- var initialThickness = profile.defaultBorderWidth;
57010
- var rectangleOptions = {
57011
- id: this.randomId(),
57012
- fill: null,
57013
- stroke: profile.defaultBorderColor,
57014
- strokeWidth: initialThickness
57015
- };
57016
- var fabricRect = new fabric_1.fabric.Rect(rectangleOptions);
57017
- this.fabricCanvas.add(fabricRect);
57018
- var object = new border_1.Border(this, fabricRect);
57019
- this.trackNewObject(object);
57020
- this.fabricCanvas.setActiveObject(fabricRect);
57021
- this.syncObjectList();
57022
- return new rxjs_1.BehaviorSubject(object);
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
- var rectOptions = {
57030
- id: this.randomId(),
57031
- width: 2,
57032
- height: 10,
57033
- top: 0,
57034
- left: 0,
57035
- fill: "#000000"
57036
- };
57037
- var fabricRect = new fabric_1.fabric.Rect(rectOptions);
57038
- this.fabricCanvas.add(fabricRect);
57039
- var object = new vertical_rule_1.VerticalRule(this, fabricRect);
57040
- this.trackNewObject(object);
57041
- this.fabricCanvas.setActiveObject(fabricRect);
57042
- this.syncObjectList();
57043
- return new rxjs_1.BehaviorSubject(object);
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
- var rectOptions = {
57051
- id: this.randomId(),
57052
- width: 10,
57053
- height: 2,
57054
- top: 0,
57055
- left: 0,
57056
- fill: "#000000"
57057
- };
57058
- var fabricRect = new fabric_1.fabric.Rect(rectOptions);
57059
- this.fabricCanvas.add(fabricRect);
57060
- var object = new horizontal_rule_1.HorizontalRule(this, fabricRect);
57061
- this.trackNewObject(object);
57062
- this.fabricCanvas.setActiveObject(fabricRect);
57063
- this.syncObjectList();
57064
- return new rxjs_1.BehaviorSubject(object);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"
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
  ```