@leapfrog/interactive-canvas 1.8.1 → 1.9.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.
package/dist/index.d.ts CHANGED
@@ -15,8 +15,9 @@ export * from "./mutator/mutable-background-color.interface";
15
15
  export * from "./mutator/mutable-color.interface";
16
16
  export * from "./mutator/mutable-image.interface";
17
17
  export * from "./mutator/mutable-position.interface";
18
- export * from "./mutator/mutable-text.interface";
18
+ export * from "./mutator/mutable-stroke.interface";
19
19
  export * from "./mutator/mutable-text-style.interface";
20
+ export * from "./mutator/mutable-text.interface";
20
21
  export * from "./object/abstract-canvas-object";
21
22
  export * from "./object/canvas-object-data";
22
23
  export * from "./object/canvas-object.interface";
@@ -616,14 +616,18 @@ function isMutablePosition(object) {
616
616
  return "centerHorizontally" in object;
617
617
  }
618
618
 
619
- function isMutableText(object) {
620
- return "setText" in object;
619
+ function isMutableStroke(object) {
620
+ return "setStrokeColor" in object;
621
621
  }
622
622
 
623
623
  function isMutableTextStyle(object) {
624
624
  return "getTextSelection" in object;
625
625
  }
626
626
 
627
+ function isMutableText(object) {
628
+ return "setText" in object;
629
+ }
630
+
627
631
  /**
628
632
  * Data for a persisted canvas object.
629
633
  */
@@ -657,6 +661,7 @@ var AbstractCanvasObject = /** @class */ (function () {
657
661
  this.fabricObject.on("moving", function (e) { return _this.onMove(e); });
658
662
  this.fabricObject.on("rotating", function (e) { return _this.onRotate(e); });
659
663
  this.fabricObject.on("scaling", function (e) { return _this.onScale(e); });
664
+ this.fabricObject.on("scaled", function (e) { return _this.afterScale(e); });
660
665
  }
661
666
  /**
662
667
  * @override
@@ -1006,6 +1011,10 @@ var AbstractCanvasObject = /** @class */ (function () {
1006
1011
  AbstractCanvasObject.prototype.onScale = function (event) {
1007
1012
  this.updateDimensions();
1008
1013
  };
1014
+ // noinspection JSUnusedLocalSymbols
1015
+ AbstractCanvasObject.prototype.afterScale = function (event) {
1016
+ this.updateDimensions();
1017
+ };
1009
1018
  AbstractCanvasObject.prototype.onDelete = function () {
1010
1019
  //no-op
1011
1020
  };
@@ -1596,7 +1605,6 @@ var Rectangle = /** @class */ (function (_super) {
1596
1605
  function Rectangle(canvas, fabricObject, persistedField) {
1597
1606
  var _this = _super.call(this, ObjectType.RECTANGLE, canvas, fabricObject, persistedField) || this;
1598
1607
  _this.canvas = canvas;
1599
- _this.fabricObject.set({ strokeWidth: 0 });
1600
1608
  return _this;
1601
1609
  }
1602
1610
  /**
@@ -1611,10 +1619,42 @@ var Rectangle = /** @class */ (function (_super) {
1611
1619
  * @inheritDoc
1612
1620
  */
1613
1621
  Rectangle.prototype.setColor = function (color) {
1614
- this.fabricObject.set({ fill: color, stroke: color });
1622
+ this.fabricObject.set({ fill: color });
1615
1623
  this.data.color = color;
1616
1624
  this.redraw();
1617
1625
  };
1626
+ /**
1627
+ * @override
1628
+ * @inheritDoc
1629
+ */
1630
+ Rectangle.prototype.getStrokeColor = function () {
1631
+ return this.fabricObject.stroke;
1632
+ };
1633
+ /**
1634
+ * @override
1635
+ * @inheritDoc
1636
+ */
1637
+ Rectangle.prototype.setStrokeColor = function (color) {
1638
+ this.fabricObject.set({ stroke: color });
1639
+ this.data.color = color;
1640
+ this.redraw();
1641
+ };
1642
+ /**
1643
+ * @override
1644
+ * @inheritDoc
1645
+ */
1646
+ Rectangle.prototype.getStrokeWidth = function () {
1647
+ return this.fabricObject.strokeWidth;
1648
+ };
1649
+ /**
1650
+ * @override
1651
+ * @inheritDoc
1652
+ */
1653
+ Rectangle.prototype.setStrokeWidth = function (width) {
1654
+ this.fabricObject.set({ strokeWidth: width });
1655
+ this.data.strokeWidth = width;
1656
+ this.redraw();
1657
+ };
1618
1658
  /**
1619
1659
  * @override
1620
1660
  * @inheritDoc
@@ -1657,6 +1697,16 @@ var Rectangle = /** @class */ (function (_super) {
1657
1697
  Rectangle.prototype.nudgeRight = function () {
1658
1698
  _super.prototype.nudgeInternal.call(this, +1, 0);
1659
1699
  };
1700
+ /**
1701
+ * @override
1702
+ * @inheritDoc
1703
+ */
1704
+ Rectangle.prototype.afterScale = function (event) {
1705
+ this.updateDimensions();
1706
+ var _a = this.getDimensions(), width = _a.width, height = _a.height;
1707
+ this.fabricObject.set({ scaleX: 1, scaleY: 1, width: width.px, height: height.px });
1708
+ this.updateDimensions();
1709
+ };
1660
1710
  return Rectangle;
1661
1711
  }(AbstractCanvasObject));
1662
1712
 
@@ -3452,4 +3502,4 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3452
3502
  return InteractiveCanvas;
3453
3503
  }(AbstractInteractiveCanvas));
3454
3504
 
3455
- export { AbstractCanvasObject, AbstractInteractiveCanvas, AbstractLayoutManager, AdvancedLayoutManager, Border, CanvasObjectData, Cutoff, DefaultCanvasProfile, Font, FontLibrary, HeadlessInteractiveCanvas, HorizontalRule, Image, ImageType, InteractiveCanvas, LayoutManager, MillimeterDimensions, ObjectType, PixelCanvasDimensions, Print6ColCanvasDimensions, Print8ColCanvasDimensions, Rectangle, RichText, SelectionData, StandardLayoutManager, Text, UNKNOWN_FONT, UnknownFont, VerticalRule, isMutableBackgroundColor, isMutableColor, isMutableImage, isMutablePosition, isMutableText, isMutableTextStyle };
3505
+ export { AbstractCanvasObject, AbstractInteractiveCanvas, AbstractLayoutManager, AdvancedLayoutManager, Border, CanvasObjectData, Cutoff, DefaultCanvasProfile, Font, FontLibrary, HeadlessInteractiveCanvas, HorizontalRule, Image, ImageType, InteractiveCanvas, LayoutManager, MillimeterDimensions, ObjectType, PixelCanvasDimensions, Print6ColCanvasDimensions, Print8ColCanvasDimensions, Rectangle, RichText, SelectionData, StandardLayoutManager, Text, UNKNOWN_FONT, UnknownFont, VerticalRule, isMutableBackgroundColor, isMutableColor, isMutableImage, isMutablePosition, isMutableStroke, isMutableText, isMutableTextStyle };
@@ -618,14 +618,18 @@ function isMutablePosition(object) {
618
618
  return "centerHorizontally" in object;
619
619
  }
620
620
 
621
- function isMutableText(object) {
622
- return "setText" in object;
621
+ function isMutableStroke(object) {
622
+ return "setStrokeColor" in object;
623
623
  }
624
624
 
625
625
  function isMutableTextStyle(object) {
626
626
  return "getTextSelection" in object;
627
627
  }
628
628
 
629
+ function isMutableText(object) {
630
+ return "setText" in object;
631
+ }
632
+
629
633
  /**
630
634
  * Data for a persisted canvas object.
631
635
  */
@@ -659,6 +663,7 @@ var AbstractCanvasObject = /** @class */ (function () {
659
663
  this.fabricObject.on("moving", function (e) { return _this.onMove(e); });
660
664
  this.fabricObject.on("rotating", function (e) { return _this.onRotate(e); });
661
665
  this.fabricObject.on("scaling", function (e) { return _this.onScale(e); });
666
+ this.fabricObject.on("scaled", function (e) { return _this.afterScale(e); });
662
667
  }
663
668
  /**
664
669
  * @override
@@ -1008,6 +1013,10 @@ var AbstractCanvasObject = /** @class */ (function () {
1008
1013
  AbstractCanvasObject.prototype.onScale = function (event) {
1009
1014
  this.updateDimensions();
1010
1015
  };
1016
+ // noinspection JSUnusedLocalSymbols
1017
+ AbstractCanvasObject.prototype.afterScale = function (event) {
1018
+ this.updateDimensions();
1019
+ };
1011
1020
  AbstractCanvasObject.prototype.onDelete = function () {
1012
1021
  //no-op
1013
1022
  };
@@ -1598,7 +1607,6 @@ var Rectangle = /** @class */ (function (_super) {
1598
1607
  function Rectangle(canvas, fabricObject, persistedField) {
1599
1608
  var _this = _super.call(this, exports.ObjectType.RECTANGLE, canvas, fabricObject, persistedField) || this;
1600
1609
  _this.canvas = canvas;
1601
- _this.fabricObject.set({ strokeWidth: 0 });
1602
1610
  return _this;
1603
1611
  }
1604
1612
  /**
@@ -1613,10 +1621,42 @@ var Rectangle = /** @class */ (function (_super) {
1613
1621
  * @inheritDoc
1614
1622
  */
1615
1623
  Rectangle.prototype.setColor = function (color) {
1616
- this.fabricObject.set({ fill: color, stroke: color });
1624
+ this.fabricObject.set({ fill: color });
1617
1625
  this.data.color = color;
1618
1626
  this.redraw();
1619
1627
  };
1628
+ /**
1629
+ * @override
1630
+ * @inheritDoc
1631
+ */
1632
+ Rectangle.prototype.getStrokeColor = function () {
1633
+ return this.fabricObject.stroke;
1634
+ };
1635
+ /**
1636
+ * @override
1637
+ * @inheritDoc
1638
+ */
1639
+ Rectangle.prototype.setStrokeColor = function (color) {
1640
+ this.fabricObject.set({ stroke: color });
1641
+ this.data.color = color;
1642
+ this.redraw();
1643
+ };
1644
+ /**
1645
+ * @override
1646
+ * @inheritDoc
1647
+ */
1648
+ Rectangle.prototype.getStrokeWidth = function () {
1649
+ return this.fabricObject.strokeWidth;
1650
+ };
1651
+ /**
1652
+ * @override
1653
+ * @inheritDoc
1654
+ */
1655
+ Rectangle.prototype.setStrokeWidth = function (width) {
1656
+ this.fabricObject.set({ strokeWidth: width });
1657
+ this.data.strokeWidth = width;
1658
+ this.redraw();
1659
+ };
1620
1660
  /**
1621
1661
  * @override
1622
1662
  * @inheritDoc
@@ -1659,6 +1699,16 @@ var Rectangle = /** @class */ (function (_super) {
1659
1699
  Rectangle.prototype.nudgeRight = function () {
1660
1700
  _super.prototype.nudgeInternal.call(this, +1, 0);
1661
1701
  };
1702
+ /**
1703
+ * @override
1704
+ * @inheritDoc
1705
+ */
1706
+ Rectangle.prototype.afterScale = function (event) {
1707
+ this.updateDimensions();
1708
+ var _a = this.getDimensions(), width = _a.width, height = _a.height;
1709
+ this.fabricObject.set({ scaleX: 1, scaleY: 1, width: width.px, height: height.px });
1710
+ this.updateDimensions();
1711
+ };
1662
1712
  return Rectangle;
1663
1713
  }(AbstractCanvasObject));
1664
1714
 
@@ -3482,5 +3532,6 @@ exports.isMutableBackgroundColor = isMutableBackgroundColor;
3482
3532
  exports.isMutableColor = isMutableColor;
3483
3533
  exports.isMutableImage = isMutableImage;
3484
3534
  exports.isMutablePosition = isMutablePosition;
3535
+ exports.isMutableStroke = isMutableStroke;
3485
3536
  exports.isMutableText = isMutableText;
3486
3537
  exports.isMutableTextStyle = isMutableTextStyle;
@@ -1,6 +1,6 @@
1
1
  import { ICanvasObject } from "..";
2
2
  export interface IMutableColor extends ICanvasObject {
3
- getColor(): string;
4
- setColor(color: string): void;
3
+ getColor(): string | null;
4
+ setColor(color: string | null): void;
5
5
  }
6
6
  export declare function isMutableColor(object: any): object is IMutableColor;
@@ -0,0 +1,8 @@
1
+ import { ICanvasObject } from "..";
2
+ export interface IMutableStroke extends ICanvasObject {
3
+ getStrokeColor(): string | null;
4
+ setStrokeColor(color: string | null): void;
5
+ getStrokeWidth(): number;
6
+ setStrokeWidth(width: number): void;
7
+ }
8
+ export declare function isMutableStroke(object: any): object is IMutableStroke;
@@ -76,7 +76,7 @@ export interface IMutableTextStyle extends IMutableText {
76
76
  * Set the text background color.
77
77
  * @param color New value.
78
78
  */
79
- setTextBackgroundColor(color: string): void;
79
+ setTextBackgroundColor(color: string | null): void;
80
80
  }
81
81
  export interface ITextSelection {
82
82
  /**
@@ -196,6 +196,7 @@ export declare abstract class AbstractCanvasObject<T extends Object> implements
196
196
  protected onMove(event: any): void;
197
197
  protected onRotate(event: any): void;
198
198
  protected onScale(event: any): void;
199
+ protected afterScale(event: any): void;
199
200
  protected onDelete(): void;
200
201
  protected preventLeavingCanvas(): void;
201
202
  protected getCanvasOverflow(): IOverflow;
@@ -1,12 +1,12 @@
1
1
  import { ICanvasObject } from "../canvas-object.interface";
2
- import { IInteractiveCanvas, IMutableColor, IMutablePosition } from "../..";
2
+ import { IInteractiveCanvas, IMutableColor, IMutablePosition, IMutableStroke } from "../..";
3
3
  import { AbstractCanvasObject } from "../abstract-canvas-object";
4
4
  import { CanvasObjectData } from "../canvas-object-data";
5
5
  import { fabric } from "fabric";
6
6
  /**
7
7
  * Rectangle field. A basic block of color that can be moved and scaled.
8
8
  */
9
- export interface IRectangle extends ICanvasObject, IMutableColor, IMutablePosition {
9
+ export interface IRectangle extends ICanvasObject, IMutableStroke, IMutableColor, IMutablePosition {
10
10
  }
11
11
  export declare class Rectangle extends AbstractCanvasObject<fabric.Rect> implements IRectangle {
12
12
  constructor(canvas: IInteractiveCanvas, fabricObject: fabric.Rect, persistedField?: CanvasObjectData);
@@ -20,6 +20,26 @@ export declare class Rectangle extends AbstractCanvasObject<fabric.Rect> impleme
20
20
  * @inheritDoc
21
21
  */
22
22
  setColor(color: string): void;
23
+ /**
24
+ * @override
25
+ * @inheritDoc
26
+ */
27
+ getStrokeColor(): string | null;
28
+ /**
29
+ * @override
30
+ * @inheritDoc
31
+ */
32
+ setStrokeColor(color: string | null): void;
33
+ /**
34
+ * @override
35
+ * @inheritDoc
36
+ */
37
+ getStrokeWidth(): number;
38
+ /**
39
+ * @override
40
+ * @inheritDoc
41
+ */
42
+ setStrokeWidth(width: number): void;
23
43
  /**
24
44
  * @override
25
45
  * @inheritDoc
@@ -50,4 +70,9 @@ export declare class Rectangle extends AbstractCanvasObject<fabric.Rect> impleme
50
70
  * @inheritDoc
51
71
  */
52
72
  nudgeRight(): void;
73
+ /**
74
+ * @override
75
+ * @inheritDoc
76
+ */
77
+ protected afterScale(event: any): void;
53
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "1.8.1",
3
+ "version": "1.9.1",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"