@leapfrog/interactive-canvas 1.1.0 → 1.3.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.
@@ -844,6 +844,55 @@ var AbstractCanvasObject = /** @class */ (function () {
844
844
  this.canvas.notifyObjectListChanged();
845
845
  this.updateFabricObjectBehavior();
846
846
  };
847
+ /**
848
+ * @override
849
+ * @inheritDoc
850
+ */
851
+ AbstractCanvasObject.prototype.setLeft = function (left) {
852
+ this.setPosition({ left: left });
853
+ };
854
+ /**
855
+ * @override
856
+ * @inheritDoc
857
+ */
858
+ AbstractCanvasObject.prototype.setTop = function (top) {
859
+ this.setPosition({ top: top });
860
+ };
861
+ /**
862
+ * @override
863
+ * @inheritDoc
864
+ */
865
+ AbstractCanvasObject.prototype.setHeight = function (height) {
866
+ this.setPosition({ height: height });
867
+ };
868
+ /**
869
+ * @override
870
+ * @inheritDoc
871
+ */
872
+ AbstractCanvasObject.prototype.setWidth = function (width) {
873
+ this.setPosition({ width: width });
874
+ };
875
+ /**
876
+ * @override
877
+ * @inheritDoc
878
+ */
879
+ AbstractCanvasObject.prototype.setAngle = function (angle) {
880
+ this.setPosition({ angle: angle });
881
+ };
882
+ /**
883
+ * @override
884
+ * @inheritDoc
885
+ */
886
+ AbstractCanvasObject.prototype.setScaleX = function (scale) {
887
+ this.setPosition({ scaleX: scale });
888
+ };
889
+ /**
890
+ * @override
891
+ * @inheritDoc
892
+ */
893
+ AbstractCanvasObject.prototype.setScaleY = function (scale) {
894
+ this.setPosition({ scaleY: scale });
895
+ };
847
896
  /**
848
897
  * Get the underlying fabric object.
849
898
  * (Internal use only, do not expose this outside the canvas module).
@@ -861,6 +910,14 @@ var AbstractCanvasObject = /** @class */ (function () {
861
910
  this.fabricObject.set({ width: position.width / scale.x });
862
911
  if (position.height != undefined)
863
912
  this.fabricObject.set({ height: position.height / scale.y });
913
+ if (position.angle != undefined)
914
+ this.fabricObject.set({ angle: position.angle });
915
+ if (position.scaleX != undefined)
916
+ this.fabricObject.set({ scaleX: position.scaleX });
917
+ if (position.scaleY != undefined)
918
+ this.fabricObject.set({ scaleY: position.scaleY });
919
+ this.setCoords();
920
+ this.redraw();
864
921
  };
865
922
  AbstractCanvasObject.prototype.setCoords = function () {
866
923
  this.fabricObject.setCoords();
@@ -1282,14 +1339,6 @@ var HorizontalRule = /** @class */ (function (_super) {
1282
1339
  HorizontalRule.prototype.centerVertically = function () {
1283
1340
  _super.prototype.centerVerticallyInternal.call(this);
1284
1341
  };
1285
- /**
1286
- * @override
1287
- * @inheritDoc
1288
- */
1289
- HorizontalRule.prototype.setHeight = function (height) {
1290
- this.setPosition({ height: height });
1291
- this.canvas.notifyObjectListChanged();
1292
- };
1293
1342
  /**
1294
1343
  * @override
1295
1344
  * @inheritDoc
@@ -1394,14 +1443,6 @@ var Image = /** @class */ (function (_super) {
1394
1443
  Image.prototype.centerVertically = function () {
1395
1444
  _super.prototype.centerVerticallyInternal.call(this);
1396
1445
  };
1397
- /**
1398
- * @override
1399
- * @inheritDoc
1400
- */
1401
- Image.prototype.setHeight = function (height) {
1402
- this.setPosition({ height: height });
1403
- this.canvas.notifyObjectListChanged();
1404
- };
1405
1446
  /**
1406
1447
  * @override
1407
1448
  * @inheritDoc
@@ -1536,14 +1577,6 @@ var Rectangle = /** @class */ (function (_super) {
1536
1577
  Rectangle.prototype.centerVertically = function () {
1537
1578
  _super.prototype.centerVerticallyInternal.call(this);
1538
1579
  };
1539
- /**
1540
- * @override
1541
- * @inheritDoc
1542
- */
1543
- Rectangle.prototype.setHeight = function (height) {
1544
- this.setPosition({ height: height });
1545
- this.canvas.notifyObjectListChanged();
1546
- };
1547
1580
  /**
1548
1581
  * @override
1549
1582
  * @inheritDoc
@@ -1837,13 +1870,6 @@ var Text = /** @class */ (function (_super) {
1837
1870
  Text.prototype.centerVertically = function () {
1838
1871
  _super.prototype.centerVerticallyInternal.call(this);
1839
1872
  };
1840
- /**
1841
- * @override
1842
- * @inheritDoc
1843
- */
1844
- Text.prototype.setHeight = function (height) {
1845
- //no-op
1846
- };
1847
1873
  /**
1848
1874
  * @override
1849
1875
  * @inheritDoc
@@ -2061,29 +2087,22 @@ var Text = /** @class */ (function (_super) {
2061
2087
  var bullets = fabricText._bullets;
2062
2088
  if (bullets && bullets[lineIndex]) {
2063
2089
  var bullet = bullets[lineIndex];
2064
- var bulletIndent = 10;
2065
- var bulletLeft = fabricText.left + (left - fabricText._getLeftOffset() - bulletIndent) * fabricText.scaleX;
2066
- if (bullet.left !== bulletLeft) {
2067
- bullet.set({ left: bulletLeft });
2068
- }
2069
- /**
2070
- * What an out-and-out mess... this calculation is a joke, and the bulletOffset is just an approximation of values that look ok for
2071
- * the font sizes we use. The 'top' value provided is actutally the... bottom? of the line... and not the line... the bottom of where
2072
- * the font is rendered... subtracting the `fabricText.getHeightOfLine(lineIndex)` line hieght doesn't give you the top, because the
2073
- * line height is actually the height of the font plus the excess line height added via the text line-height property.
2074
- * I couldn't figure out how to get the actual top of the line in two days of trying to understand this ridiculous library.
2075
- * So, here... bullets. That sort of work... sometimes.
2076
- */
2077
- var textOriginTop = fabricText.top + (fabricText.height / 2);
2078
2090
  var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
2079
- var bulletOffset = ((fontSize + 6) / 2);
2080
- var bulletTop = textOriginTop + top - bulletOffset;
2081
- if (bullet.top !== bulletTop) {
2082
- bullet.set({ top: bulletTop });
2083
- }
2084
- if (bullet.fill !== fabricText.fill) {
2085
- bullet.set({ fill: fabricText.fill });
2086
- }
2091
+ var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
2092
+ var radius = fontSize / 5;
2093
+ var angle = fabricText.angle;
2094
+ var theta = angle * Math.PI / 180;
2095
+ var x = -radius * 2;
2096
+ var y = (fabricText.height / 2) + top - (fontSize / 1.5);
2097
+ var xOffset = (x * Math.cos(theta)) - (y * Math.sin(theta));
2098
+ var yOffset = (x * Math.sin(theta)) + (y * Math.cos(theta));
2099
+ var bulletCenterOffset = [-radius * Math.sqrt(2) / 2, -radius * Math.sqrt(2) / 2];
2100
+ bullet.set({
2101
+ radius: radius,
2102
+ fill: color,
2103
+ left: fabricText.left + xOffset + bulletCenterOffset[0],
2104
+ top: fabricText.top + yOffset + bulletCenterOffset[1]
2105
+ });
2087
2106
  }
2088
2107
  originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
2089
2108
  };
@@ -2235,14 +2254,6 @@ var VerticalRule = /** @class */ (function (_super) {
2235
2254
  VerticalRule.prototype.centerVertically = function () {
2236
2255
  _super.prototype.centerVerticallyInternal.call(this);
2237
2256
  };
2238
- /**
2239
- * @override
2240
- * @inheritDoc
2241
- */
2242
- VerticalRule.prototype.setHeight = function (height) {
2243
- this.setPosition({ height: height });
2244
- this.canvas.notifyObjectListChanged();
2245
- };
2246
2257
  /**
2247
2258
  * @override
2248
2259
  * @inheritDoc
@@ -2461,7 +2472,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2461
2472
  this.updateCanvasDimensions(dimensions, this.zoom$.value);
2462
2473
  this.dimensions$.next(dimensions);
2463
2474
  this.onDimensionsChange();
2464
- this.notifyObjectListChanged();
2465
2475
  };
2466
2476
  /**
2467
2477
  * @override
@@ -2470,7 +2480,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2470
2480
  AbstractInteractiveCanvas.prototype.setBaseDimensions = function (dimensions) {
2471
2481
  this.baseDimensions = dimensions;
2472
2482
  this.setDimensions(dimensions);
2473
- this.notifyObjectListChanged();
2474
2483
  };
2475
2484
  /**
2476
2485
  * @override
@@ -846,6 +846,55 @@ var AbstractCanvasObject = /** @class */ (function () {
846
846
  this.canvas.notifyObjectListChanged();
847
847
  this.updateFabricObjectBehavior();
848
848
  };
849
+ /**
850
+ * @override
851
+ * @inheritDoc
852
+ */
853
+ AbstractCanvasObject.prototype.setLeft = function (left) {
854
+ this.setPosition({ left: left });
855
+ };
856
+ /**
857
+ * @override
858
+ * @inheritDoc
859
+ */
860
+ AbstractCanvasObject.prototype.setTop = function (top) {
861
+ this.setPosition({ top: top });
862
+ };
863
+ /**
864
+ * @override
865
+ * @inheritDoc
866
+ */
867
+ AbstractCanvasObject.prototype.setHeight = function (height) {
868
+ this.setPosition({ height: height });
869
+ };
870
+ /**
871
+ * @override
872
+ * @inheritDoc
873
+ */
874
+ AbstractCanvasObject.prototype.setWidth = function (width) {
875
+ this.setPosition({ width: width });
876
+ };
877
+ /**
878
+ * @override
879
+ * @inheritDoc
880
+ */
881
+ AbstractCanvasObject.prototype.setAngle = function (angle) {
882
+ this.setPosition({ angle: angle });
883
+ };
884
+ /**
885
+ * @override
886
+ * @inheritDoc
887
+ */
888
+ AbstractCanvasObject.prototype.setScaleX = function (scale) {
889
+ this.setPosition({ scaleX: scale });
890
+ };
891
+ /**
892
+ * @override
893
+ * @inheritDoc
894
+ */
895
+ AbstractCanvasObject.prototype.setScaleY = function (scale) {
896
+ this.setPosition({ scaleY: scale });
897
+ };
849
898
  /**
850
899
  * Get the underlying fabric object.
851
900
  * (Internal use only, do not expose this outside the canvas module).
@@ -863,6 +912,14 @@ var AbstractCanvasObject = /** @class */ (function () {
863
912
  this.fabricObject.set({ width: position.width / scale.x });
864
913
  if (position.height != undefined)
865
914
  this.fabricObject.set({ height: position.height / scale.y });
915
+ if (position.angle != undefined)
916
+ this.fabricObject.set({ angle: position.angle });
917
+ if (position.scaleX != undefined)
918
+ this.fabricObject.set({ scaleX: position.scaleX });
919
+ if (position.scaleY != undefined)
920
+ this.fabricObject.set({ scaleY: position.scaleY });
921
+ this.setCoords();
922
+ this.redraw();
866
923
  };
867
924
  AbstractCanvasObject.prototype.setCoords = function () {
868
925
  this.fabricObject.setCoords();
@@ -1284,14 +1341,6 @@ var HorizontalRule = /** @class */ (function (_super) {
1284
1341
  HorizontalRule.prototype.centerVertically = function () {
1285
1342
  _super.prototype.centerVerticallyInternal.call(this);
1286
1343
  };
1287
- /**
1288
- * @override
1289
- * @inheritDoc
1290
- */
1291
- HorizontalRule.prototype.setHeight = function (height) {
1292
- this.setPosition({ height: height });
1293
- this.canvas.notifyObjectListChanged();
1294
- };
1295
1344
  /**
1296
1345
  * @override
1297
1346
  * @inheritDoc
@@ -1396,14 +1445,6 @@ var Image = /** @class */ (function (_super) {
1396
1445
  Image.prototype.centerVertically = function () {
1397
1446
  _super.prototype.centerVerticallyInternal.call(this);
1398
1447
  };
1399
- /**
1400
- * @override
1401
- * @inheritDoc
1402
- */
1403
- Image.prototype.setHeight = function (height) {
1404
- this.setPosition({ height: height });
1405
- this.canvas.notifyObjectListChanged();
1406
- };
1407
1448
  /**
1408
1449
  * @override
1409
1450
  * @inheritDoc
@@ -1538,14 +1579,6 @@ var Rectangle = /** @class */ (function (_super) {
1538
1579
  Rectangle.prototype.centerVertically = function () {
1539
1580
  _super.prototype.centerVerticallyInternal.call(this);
1540
1581
  };
1541
- /**
1542
- * @override
1543
- * @inheritDoc
1544
- */
1545
- Rectangle.prototype.setHeight = function (height) {
1546
- this.setPosition({ height: height });
1547
- this.canvas.notifyObjectListChanged();
1548
- };
1549
1582
  /**
1550
1583
  * @override
1551
1584
  * @inheritDoc
@@ -1839,13 +1872,6 @@ var Text = /** @class */ (function (_super) {
1839
1872
  Text.prototype.centerVertically = function () {
1840
1873
  _super.prototype.centerVerticallyInternal.call(this);
1841
1874
  };
1842
- /**
1843
- * @override
1844
- * @inheritDoc
1845
- */
1846
- Text.prototype.setHeight = function (height) {
1847
- //no-op
1848
- };
1849
1875
  /**
1850
1876
  * @override
1851
1877
  * @inheritDoc
@@ -2063,29 +2089,22 @@ var Text = /** @class */ (function (_super) {
2063
2089
  var bullets = fabricText._bullets;
2064
2090
  if (bullets && bullets[lineIndex]) {
2065
2091
  var bullet = bullets[lineIndex];
2066
- var bulletIndent = 10;
2067
- var bulletLeft = fabricText.left + (left - fabricText._getLeftOffset() - bulletIndent) * fabricText.scaleX;
2068
- if (bullet.left !== bulletLeft) {
2069
- bullet.set({ left: bulletLeft });
2070
- }
2071
- /**
2072
- * What an out-and-out mess... this calculation is a joke, and the bulletOffset is just an approximation of values that look ok for
2073
- * the font sizes we use. The 'top' value provided is actutally the... bottom? of the line... and not the line... the bottom of where
2074
- * the font is rendered... subtracting the `fabricText.getHeightOfLine(lineIndex)` line hieght doesn't give you the top, because the
2075
- * line height is actually the height of the font plus the excess line height added via the text line-height property.
2076
- * I couldn't figure out how to get the actual top of the line in two days of trying to understand this ridiculous library.
2077
- * So, here... bullets. That sort of work... sometimes.
2078
- */
2079
- var textOriginTop = fabricText.top + (fabricText.height / 2);
2080
2092
  var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
2081
- var bulletOffset = ((fontSize + 6) / 2);
2082
- var bulletTop = textOriginTop + top - bulletOffset;
2083
- if (bullet.top !== bulletTop) {
2084
- bullet.set({ top: bulletTop });
2085
- }
2086
- if (bullet.fill !== fabricText.fill) {
2087
- bullet.set({ fill: fabricText.fill });
2088
- }
2093
+ var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
2094
+ var radius = fontSize / 5;
2095
+ var angle = fabricText.angle;
2096
+ var theta = angle * Math.PI / 180;
2097
+ var x = -radius * 2;
2098
+ var y = (fabricText.height / 2) + top - (fontSize / 1.5);
2099
+ var xOffset = (x * Math.cos(theta)) - (y * Math.sin(theta));
2100
+ var yOffset = (x * Math.sin(theta)) + (y * Math.cos(theta));
2101
+ var bulletCenterOffset = [-radius * Math.sqrt(2) / 2, -radius * Math.sqrt(2) / 2];
2102
+ bullet.set({
2103
+ radius: radius,
2104
+ fill: color,
2105
+ left: fabricText.left + xOffset + bulletCenterOffset[0],
2106
+ top: fabricText.top + yOffset + bulletCenterOffset[1]
2107
+ });
2089
2108
  }
2090
2109
  originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
2091
2110
  };
@@ -2237,14 +2256,6 @@ var VerticalRule = /** @class */ (function (_super) {
2237
2256
  VerticalRule.prototype.centerVertically = function () {
2238
2257
  _super.prototype.centerVerticallyInternal.call(this);
2239
2258
  };
2240
- /**
2241
- * @override
2242
- * @inheritDoc
2243
- */
2244
- VerticalRule.prototype.setHeight = function (height) {
2245
- this.setPosition({ height: height });
2246
- this.canvas.notifyObjectListChanged();
2247
- };
2248
2259
  /**
2249
2260
  * @override
2250
2261
  * @inheritDoc
@@ -2461,7 +2472,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2461
2472
  this.updateCanvasDimensions(dimensions, this.zoom$.value);
2462
2473
  this.dimensions$.next(dimensions);
2463
2474
  this.onDimensionsChange();
2464
- this.notifyObjectListChanged();
2465
2475
  };
2466
2476
  /**
2467
2477
  * @override
@@ -2470,7 +2480,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2470
2480
  AbstractInteractiveCanvas.prototype.setBaseDimensions = function (dimensions) {
2471
2481
  this.baseDimensions = dimensions;
2472
2482
  this.setDimensions(dimensions);
2473
- this.notifyObjectListChanged();
2474
2483
  };
2475
2484
  /**
2476
2485
  * @override
@@ -8,11 +8,41 @@ export interface IMutablePosition extends ICanvasObject {
8
8
  * Center the object vertically on the canvas.
9
9
  */
10
10
  centerVertically(): void;
11
+ /**
12
+ * Set the left value of the element.
13
+ * @param left New left value.
14
+ */
15
+ setLeft(left: number): void;
16
+ /**
17
+ * Set the top value of the element.
18
+ * @param top New top value.
19
+ */
20
+ setTop(top: number): void;
11
21
  /**
12
22
  * Set the height of the element.
13
23
  * @param height New height.
14
24
  */
15
25
  setHeight(height: number): void;
26
+ /**
27
+ * Set the width of the element.
28
+ * @param width New width.
29
+ */
30
+ setWidth(width: number): void;
31
+ /**
32
+ * Set the angle of the element.
33
+ * @param angle New angle.
34
+ */
35
+ setAngle(angle: number): void;
36
+ /**
37
+ * Set the x scale of the element.
38
+ * @param scale New scale.
39
+ */
40
+ setScaleX(scale: number): void;
41
+ /**
42
+ * Set the y scale of the element.
43
+ * @param scale New scale.
44
+ */
45
+ setScaleY(scale: number): void;
16
46
  /**
17
47
  * Nudge the object upward.
18
48
  */
@@ -123,6 +123,41 @@ export declare abstract class AbstractCanvasObject<T extends Object> implements
123
123
  * @inheritDoc
124
124
  */
125
125
  setPinToBottom(value?: boolean): void;
126
+ /**
127
+ * @override
128
+ * @inheritDoc
129
+ */
130
+ setLeft(left: number): void;
131
+ /**
132
+ * @override
133
+ * @inheritDoc
134
+ */
135
+ setTop(top: number): void;
136
+ /**
137
+ * @override
138
+ * @inheritDoc
139
+ */
140
+ setHeight(height: number): void;
141
+ /**
142
+ * @override
143
+ * @inheritDoc
144
+ */
145
+ setWidth(width: number): void;
146
+ /**
147
+ * @override
148
+ * @inheritDoc
149
+ */
150
+ setAngle(angle: number): void;
151
+ /**
152
+ * @override
153
+ * @inheritDoc
154
+ */
155
+ setScaleX(scale: number): void;
156
+ /**
157
+ * @override
158
+ * @inheritDoc
159
+ */
160
+ setScaleY(scale: number): void;
126
161
  /**
127
162
  * Get the underlying fabric object.
128
163
  * (Internal use only, do not expose this outside the canvas module).
@@ -60,11 +60,6 @@ export declare class HorizontalRule extends AbstractCanvasObject<fabric.Rect> im
60
60
  * @inheritDoc
61
61
  */
62
62
  centerVertically(): void;
63
- /**
64
- * @override
65
- * @inheritDoc
66
- */
67
- setHeight(height: number): void;
68
63
  /**
69
64
  * @override
70
65
  * @inheritDoc
@@ -44,11 +44,6 @@ export declare class Image extends AbstractCanvasObject<fabric.Image> implements
44
44
  * @inheritDoc
45
45
  */
46
46
  centerVertically(): void;
47
- /**
48
- * @override
49
- * @inheritDoc
50
- */
51
- setHeight(height: number): void;
52
47
  /**
53
48
  * @override
54
49
  * @inheritDoc
@@ -30,11 +30,6 @@ export declare class Rectangle extends AbstractCanvasObject<fabric.Rect> impleme
30
30
  * @inheritDoc
31
31
  */
32
32
  centerVertically(): void;
33
- /**
34
- * @override
35
- * @inheritDoc
36
- */
37
- setHeight(height: number): void;
38
33
  /**
39
34
  * @override
40
35
  * @inheritDoc
@@ -157,11 +157,6 @@ export declare class Text extends AbstractCanvasObject<fabric.Textbox> implement
157
157
  * @inheritDoc
158
158
  */
159
159
  centerVertically(): void;
160
- /**
161
- * @override
162
- * @inheritDoc
163
- */
164
- setHeight(height: number): void;
165
160
  /**
166
161
  * @override
167
162
  * @inheritDoc
@@ -60,11 +60,6 @@ export declare class VerticalRule extends AbstractCanvasObject<fabric.Rect> impl
60
60
  * @inheritDoc
61
61
  */
62
62
  centerVertically(): void;
63
- /**
64
- * @override
65
- * @inheritDoc
66
- */
67
- setHeight(height: number): void;
68
63
  /**
69
64
  * @override
70
65
  * @inheritDoc
@@ -3,4 +3,7 @@ export interface IPosition {
3
3
  readonly left?: number;
4
4
  readonly width?: number;
5
5
  readonly height?: number;
6
+ readonly angle?: number;
7
+ readonly scaleX?: number;
8
+ readonly scaleY?: number;
6
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"