@leapfrog/interactive-canvas 1.2.0 → 1.4.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.
|
@@ -643,6 +643,7 @@ var AbstractCanvasObject = /** @class */ (function () {
|
|
|
643
643
|
this.fabricObject = fabricObject;
|
|
644
644
|
this.data = data ? data : new CanvasObjectData(type, this.fabricObject.id);
|
|
645
645
|
this.dimensions$ = new BehaviorSubject(new FieldDimensions(this.fabricObject, this.canvas));
|
|
646
|
+
this.opacity$ = new BehaviorSubject(this.fabricObject.opacity);
|
|
646
647
|
this.updatePinToBottomDistance();
|
|
647
648
|
this.canvas.getProfile$().subscribe(function (profile) { return _this.onProfileChange(profile); });
|
|
648
649
|
this.canvas.getLayoutManager$().subscribe(function (layoutManager) { return _this.onLayoutManagerChange(layoutManager); });
|
|
@@ -714,6 +715,29 @@ var AbstractCanvasObject = /** @class */ (function () {
|
|
|
714
715
|
AbstractCanvasObject.prototype.getDimensions$ = function () {
|
|
715
716
|
return this.dimensions$;
|
|
716
717
|
};
|
|
718
|
+
/**
|
|
719
|
+
* @override
|
|
720
|
+
* @inheritDoc
|
|
721
|
+
*/
|
|
722
|
+
AbstractCanvasObject.prototype.getOpacity = function () {
|
|
723
|
+
return this.opacity$.value;
|
|
724
|
+
};
|
|
725
|
+
/**
|
|
726
|
+
* @override
|
|
727
|
+
* @inheritDoc
|
|
728
|
+
*/
|
|
729
|
+
AbstractCanvasObject.prototype.getOpacity$ = function () {
|
|
730
|
+
return this.opacity$;
|
|
731
|
+
};
|
|
732
|
+
/**
|
|
733
|
+
* @override
|
|
734
|
+
* @inheritDoc
|
|
735
|
+
*/
|
|
736
|
+
AbstractCanvasObject.prototype.setOpacity = function (value) {
|
|
737
|
+
this.fabricObject.set({ opacity: value });
|
|
738
|
+
this.opacity$.next(value);
|
|
739
|
+
this.redraw();
|
|
740
|
+
};
|
|
717
741
|
/**
|
|
718
742
|
* @override
|
|
719
743
|
* @inheritDoc
|
|
@@ -916,7 +940,8 @@ var AbstractCanvasObject = /** @class */ (function () {
|
|
|
916
940
|
this.fabricObject.set({ scaleX: position.scaleX });
|
|
917
941
|
if (position.scaleY != undefined)
|
|
918
942
|
this.fabricObject.set({ scaleY: position.scaleY });
|
|
919
|
-
this.
|
|
943
|
+
this.setCoords();
|
|
944
|
+
this.redraw();
|
|
920
945
|
};
|
|
921
946
|
AbstractCanvasObject.prototype.setCoords = function () {
|
|
922
947
|
this.fabricObject.setCoords();
|
|
@@ -2086,29 +2111,22 @@ var Text = /** @class */ (function (_super) {
|
|
|
2086
2111
|
var bullets = fabricText._bullets;
|
|
2087
2112
|
if (bullets && bullets[lineIndex]) {
|
|
2088
2113
|
var bullet = bullets[lineIndex];
|
|
2089
|
-
var bulletIndent = 10;
|
|
2090
|
-
var bulletLeft = fabricText.left + (left - fabricText._getLeftOffset() - bulletIndent) * fabricText.scaleX;
|
|
2091
|
-
if (bullet.left !== bulletLeft) {
|
|
2092
|
-
bullet.set({ left: bulletLeft });
|
|
2093
|
-
}
|
|
2094
|
-
/**
|
|
2095
|
-
* What an out-and-out mess... this calculation is a joke, and the bulletOffset is just an approximation of values that look ok for
|
|
2096
|
-
* the font sizes we use. The 'top' value provided is actutally the... bottom? of the line... and not the line... the bottom of where
|
|
2097
|
-
* the font is rendered... subtracting the `fabricText.getHeightOfLine(lineIndex)` line hieght doesn't give you the top, because the
|
|
2098
|
-
* line height is actually the height of the font plus the excess line height added via the text line-height property.
|
|
2099
|
-
* I couldn't figure out how to get the actual top of the line in two days of trying to understand this ridiculous library.
|
|
2100
|
-
* So, here... bullets. That sort of work... sometimes.
|
|
2101
|
-
*/
|
|
2102
|
-
var textOriginTop = fabricText.top + (fabricText.height / 2);
|
|
2103
2114
|
var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
|
|
2104
|
-
var
|
|
2105
|
-
var
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2115
|
+
var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
|
|
2116
|
+
var radius = fontSize / 5;
|
|
2117
|
+
var angle = fabricText.angle;
|
|
2118
|
+
var theta = angle * Math.PI / 180;
|
|
2119
|
+
var x = -radius * 2;
|
|
2120
|
+
var y = (fabricText.height / 2) + top - (fontSize / 1.5);
|
|
2121
|
+
var xOffset = (x * Math.cos(theta)) - (y * Math.sin(theta));
|
|
2122
|
+
var yOffset = (x * Math.sin(theta)) + (y * Math.cos(theta));
|
|
2123
|
+
var bulletCenterOffset = [-radius * Math.sqrt(2) / 2, -radius * Math.sqrt(2) / 2];
|
|
2124
|
+
bullet.set({
|
|
2125
|
+
radius: radius,
|
|
2126
|
+
fill: color,
|
|
2127
|
+
left: fabricText.left + xOffset + bulletCenterOffset[0],
|
|
2128
|
+
top: fabricText.top + yOffset + bulletCenterOffset[1]
|
|
2129
|
+
});
|
|
2112
2130
|
}
|
|
2113
2131
|
originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
|
|
2114
2132
|
};
|
|
@@ -2478,7 +2496,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2478
2496
|
this.updateCanvasDimensions(dimensions, this.zoom$.value);
|
|
2479
2497
|
this.dimensions$.next(dimensions);
|
|
2480
2498
|
this.onDimensionsChange();
|
|
2481
|
-
this.notifyObjectListChanged();
|
|
2482
2499
|
};
|
|
2483
2500
|
/**
|
|
2484
2501
|
* @override
|
|
@@ -2487,7 +2504,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2487
2504
|
AbstractInteractiveCanvas.prototype.setBaseDimensions = function (dimensions) {
|
|
2488
2505
|
this.baseDimensions = dimensions;
|
|
2489
2506
|
this.setDimensions(dimensions);
|
|
2490
|
-
this.notifyObjectListChanged();
|
|
2491
2507
|
};
|
|
2492
2508
|
/**
|
|
2493
2509
|
* @override
|
|
@@ -2791,7 +2807,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2791
2807
|
return __generator(this, function (_a) {
|
|
2792
2808
|
rectOptions = {
|
|
2793
2809
|
id: this.randomId(),
|
|
2794
|
-
width:
|
|
2810
|
+
width: 1,
|
|
2795
2811
|
height: 10,
|
|
2796
2812
|
top: 0,
|
|
2797
2813
|
left: 0,
|
|
@@ -2818,7 +2834,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2818
2834
|
rectOptions = {
|
|
2819
2835
|
id: this.randomId(),
|
|
2820
2836
|
width: 10,
|
|
2821
|
-
height:
|
|
2837
|
+
height: 1,
|
|
2822
2838
|
top: 0,
|
|
2823
2839
|
left: 0,
|
|
2824
2840
|
fill: "#000000"
|
|
@@ -645,6 +645,7 @@ var AbstractCanvasObject = /** @class */ (function () {
|
|
|
645
645
|
this.fabricObject = fabricObject;
|
|
646
646
|
this.data = data ? data : new CanvasObjectData(type, this.fabricObject.id);
|
|
647
647
|
this.dimensions$ = new rxjs.BehaviorSubject(new FieldDimensions(this.fabricObject, this.canvas));
|
|
648
|
+
this.opacity$ = new rxjs.BehaviorSubject(this.fabricObject.opacity);
|
|
648
649
|
this.updatePinToBottomDistance();
|
|
649
650
|
this.canvas.getProfile$().subscribe(function (profile) { return _this.onProfileChange(profile); });
|
|
650
651
|
this.canvas.getLayoutManager$().subscribe(function (layoutManager) { return _this.onLayoutManagerChange(layoutManager); });
|
|
@@ -716,6 +717,29 @@ var AbstractCanvasObject = /** @class */ (function () {
|
|
|
716
717
|
AbstractCanvasObject.prototype.getDimensions$ = function () {
|
|
717
718
|
return this.dimensions$;
|
|
718
719
|
};
|
|
720
|
+
/**
|
|
721
|
+
* @override
|
|
722
|
+
* @inheritDoc
|
|
723
|
+
*/
|
|
724
|
+
AbstractCanvasObject.prototype.getOpacity = function () {
|
|
725
|
+
return this.opacity$.value;
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* @override
|
|
729
|
+
* @inheritDoc
|
|
730
|
+
*/
|
|
731
|
+
AbstractCanvasObject.prototype.getOpacity$ = function () {
|
|
732
|
+
return this.opacity$;
|
|
733
|
+
};
|
|
734
|
+
/**
|
|
735
|
+
* @override
|
|
736
|
+
* @inheritDoc
|
|
737
|
+
*/
|
|
738
|
+
AbstractCanvasObject.prototype.setOpacity = function (value) {
|
|
739
|
+
this.fabricObject.set({ opacity: value });
|
|
740
|
+
this.opacity$.next(value);
|
|
741
|
+
this.redraw();
|
|
742
|
+
};
|
|
719
743
|
/**
|
|
720
744
|
* @override
|
|
721
745
|
* @inheritDoc
|
|
@@ -918,7 +942,8 @@ var AbstractCanvasObject = /** @class */ (function () {
|
|
|
918
942
|
this.fabricObject.set({ scaleX: position.scaleX });
|
|
919
943
|
if (position.scaleY != undefined)
|
|
920
944
|
this.fabricObject.set({ scaleY: position.scaleY });
|
|
921
|
-
this.
|
|
945
|
+
this.setCoords();
|
|
946
|
+
this.redraw();
|
|
922
947
|
};
|
|
923
948
|
AbstractCanvasObject.prototype.setCoords = function () {
|
|
924
949
|
this.fabricObject.setCoords();
|
|
@@ -2088,29 +2113,22 @@ var Text = /** @class */ (function (_super) {
|
|
|
2088
2113
|
var bullets = fabricText._bullets;
|
|
2089
2114
|
if (bullets && bullets[lineIndex]) {
|
|
2090
2115
|
var bullet = bullets[lineIndex];
|
|
2091
|
-
var bulletIndent = 10;
|
|
2092
|
-
var bulletLeft = fabricText.left + (left - fabricText._getLeftOffset() - bulletIndent) * fabricText.scaleX;
|
|
2093
|
-
if (bullet.left !== bulletLeft) {
|
|
2094
|
-
bullet.set({ left: bulletLeft });
|
|
2095
|
-
}
|
|
2096
|
-
/**
|
|
2097
|
-
* What an out-and-out mess... this calculation is a joke, and the bulletOffset is just an approximation of values that look ok for
|
|
2098
|
-
* the font sizes we use. The 'top' value provided is actutally the... bottom? of the line... and not the line... the bottom of where
|
|
2099
|
-
* the font is rendered... subtracting the `fabricText.getHeightOfLine(lineIndex)` line hieght doesn't give you the top, because the
|
|
2100
|
-
* line height is actually the height of the font plus the excess line height added via the text line-height property.
|
|
2101
|
-
* I couldn't figure out how to get the actual top of the line in two days of trying to understand this ridiculous library.
|
|
2102
|
-
* So, here... bullets. That sort of work... sometimes.
|
|
2103
|
-
*/
|
|
2104
|
-
var textOriginTop = fabricText.top + (fabricText.height / 2);
|
|
2105
2116
|
var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
|
|
2106
|
-
var
|
|
2107
|
-
var
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2117
|
+
var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
|
|
2118
|
+
var radius = fontSize / 5;
|
|
2119
|
+
var angle = fabricText.angle;
|
|
2120
|
+
var theta = angle * Math.PI / 180;
|
|
2121
|
+
var x = -radius * 2;
|
|
2122
|
+
var y = (fabricText.height / 2) + top - (fontSize / 1.5);
|
|
2123
|
+
var xOffset = (x * Math.cos(theta)) - (y * Math.sin(theta));
|
|
2124
|
+
var yOffset = (x * Math.sin(theta)) + (y * Math.cos(theta));
|
|
2125
|
+
var bulletCenterOffset = [-radius * Math.sqrt(2) / 2, -radius * Math.sqrt(2) / 2];
|
|
2126
|
+
bullet.set({
|
|
2127
|
+
radius: radius,
|
|
2128
|
+
fill: color,
|
|
2129
|
+
left: fabricText.left + xOffset + bulletCenterOffset[0],
|
|
2130
|
+
top: fabricText.top + yOffset + bulletCenterOffset[1]
|
|
2131
|
+
});
|
|
2114
2132
|
}
|
|
2115
2133
|
originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
|
|
2116
2134
|
};
|
|
@@ -2478,7 +2496,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2478
2496
|
this.updateCanvasDimensions(dimensions, this.zoom$.value);
|
|
2479
2497
|
this.dimensions$.next(dimensions);
|
|
2480
2498
|
this.onDimensionsChange();
|
|
2481
|
-
this.notifyObjectListChanged();
|
|
2482
2499
|
};
|
|
2483
2500
|
/**
|
|
2484
2501
|
* @override
|
|
@@ -2487,7 +2504,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2487
2504
|
AbstractInteractiveCanvas.prototype.setBaseDimensions = function (dimensions) {
|
|
2488
2505
|
this.baseDimensions = dimensions;
|
|
2489
2506
|
this.setDimensions(dimensions);
|
|
2490
|
-
this.notifyObjectListChanged();
|
|
2491
2507
|
};
|
|
2492
2508
|
/**
|
|
2493
2509
|
* @override
|
|
@@ -2791,7 +2807,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2791
2807
|
return __generator(this, function (_a) {
|
|
2792
2808
|
rectOptions = {
|
|
2793
2809
|
id: this.randomId(),
|
|
2794
|
-
width:
|
|
2810
|
+
width: 1,
|
|
2795
2811
|
height: 10,
|
|
2796
2812
|
top: 0,
|
|
2797
2813
|
left: 0,
|
|
@@ -2818,7 +2834,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2818
2834
|
rectOptions = {
|
|
2819
2835
|
id: this.randomId(),
|
|
2820
2836
|
width: 10,
|
|
2821
|
-
height:
|
|
2837
|
+
height: 1,
|
|
2822
2838
|
top: 0,
|
|
2823
2839
|
left: 0,
|
|
2824
2840
|
fill: "#000000"
|
|
@@ -10,6 +10,7 @@ export declare abstract class AbstractCanvasObject<T extends Object> implements
|
|
|
10
10
|
protected fabricObject: T;
|
|
11
11
|
protected data: CanvasObjectData;
|
|
12
12
|
private readonly dimensions$;
|
|
13
|
+
private readonly opacity$;
|
|
13
14
|
/**
|
|
14
15
|
* Create a new instance.
|
|
15
16
|
* @param type Object type.
|
|
@@ -53,6 +54,21 @@ export declare abstract class AbstractCanvasObject<T extends Object> implements
|
|
|
53
54
|
* @inheritDoc
|
|
54
55
|
*/
|
|
55
56
|
getDimensions$(): Observable<IObjectDimensions>;
|
|
57
|
+
/**
|
|
58
|
+
* @override
|
|
59
|
+
* @inheritDoc
|
|
60
|
+
*/
|
|
61
|
+
getOpacity(): number;
|
|
62
|
+
/**
|
|
63
|
+
* @override
|
|
64
|
+
* @inheritDoc
|
|
65
|
+
*/
|
|
66
|
+
getOpacity$(): Observable<number>;
|
|
67
|
+
/**
|
|
68
|
+
* @override
|
|
69
|
+
* @inheritDoc
|
|
70
|
+
*/
|
|
71
|
+
setOpacity(value: number): void;
|
|
56
72
|
/**
|
|
57
73
|
* @override
|
|
58
74
|
* @inheritDoc
|
|
@@ -34,6 +34,19 @@ export interface ICanvasObject {
|
|
|
34
34
|
* Get an observable for the field dimensions.
|
|
35
35
|
*/
|
|
36
36
|
getDimensions$(): Observable<IObjectDimensions>;
|
|
37
|
+
/**
|
|
38
|
+
* Get object opacity.
|
|
39
|
+
*/
|
|
40
|
+
getOpacity(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Get an observable for the object opacity.
|
|
43
|
+
*/
|
|
44
|
+
getOpacity$(): Observable<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Set the object opacity.
|
|
47
|
+
* @param value Opacity.
|
|
48
|
+
*/
|
|
49
|
+
setOpacity(value: number): void;
|
|
37
50
|
/**
|
|
38
51
|
* Get the component margin.
|
|
39
52
|
*/
|