@leapfrog/interactive-canvas 1.12.2 → 1.13.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.
- package/dist/abstract-interactive-canvas.d.ts +1 -0
- package/dist/headless-interactive-canvas.d.ts +1 -0
- package/dist/interactive-canvas.d.ts +1 -0
- package/dist/interactive-canvas.es.js +7 -10
- package/dist/interactive-canvas.interface.d.ts +4 -0
- package/dist/interactive-canvas.js +7 -10
- package/package.json +1 -1
|
@@ -28,6 +28,7 @@ export declare abstract class AbstractInteractiveCanvas implements IInteractiveC
|
|
|
28
28
|
protected readonly fabricCanvas: fabric.Canvas;
|
|
29
29
|
protected devicePixelRatio: number;
|
|
30
30
|
protected readonly IMAGE_CAPTURE_COEFFICIENT: number;
|
|
31
|
+
abstract readonly headless: boolean;
|
|
31
32
|
protected readonly fontLibrary: IFontLibrary;
|
|
32
33
|
protected readonly profile$: BehaviorSubject<ICanvasProfile>;
|
|
33
34
|
protected readonly layoutManager$: BehaviorSubject<ILayoutManager>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AbstractInteractiveCanvas } from "./abstract-interactive-canvas";
|
|
2
2
|
export declare class InteractiveCanvas extends AbstractInteractiveCanvas {
|
|
3
3
|
protected devicePixelRatio: number;
|
|
4
|
+
readonly headless: boolean;
|
|
4
5
|
private readonly undoStack;
|
|
5
6
|
constructor(elementId: string, devicePixelRatio: number);
|
|
6
7
|
/**
|
|
@@ -2465,6 +2465,8 @@ var Text = /** @class */ (function (_super) {
|
|
|
2465
2465
|
return this.canvas.getSelection().isText && this.textSelection$.value.length > 0;
|
|
2466
2466
|
};
|
|
2467
2467
|
Text.prototype.updateTextSelection = function () {
|
|
2468
|
+
if (this.canvas.headless)
|
|
2469
|
+
return;
|
|
2468
2470
|
this.textSelection$.next(new TextSelection(this.fabricObject, this.fontLibrary));
|
|
2469
2471
|
this.notifyCanvasOfTextChanges();
|
|
2470
2472
|
};
|
|
@@ -2786,7 +2788,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2786
2788
|
*/
|
|
2787
2789
|
AbstractInteractiveCanvas.prototype.setDimensions = function (dimensions) {
|
|
2788
2790
|
if (this.dimensionsExceedRestrictions(dimensions)) {
|
|
2789
|
-
console.
|
|
2791
|
+
console.info("Requested canvas dimensions exceed current restrictions", dimensions, this.dimensionRestrictions$.value);
|
|
2790
2792
|
this.dimensionChangeRejections$.next(dimensions);
|
|
2791
2793
|
return;
|
|
2792
2794
|
}
|
|
@@ -3339,7 +3341,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3339
3341
|
return __generator(this, function (_a) {
|
|
3340
3342
|
switch (_a.label) {
|
|
3341
3343
|
case 0:
|
|
3342
|
-
console.debug("Loading canvas state", canvasState);
|
|
3343
3344
|
this.setBaseDimensions(canvasState.dimensions);
|
|
3344
3345
|
if (!(canvasState.canvasJson != undefined)) return [3 /*break*/, 2];
|
|
3345
3346
|
json_1 = JSON.parse(canvasState.canvasJson);
|
|
@@ -3403,7 +3404,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3403
3404
|
multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
|
|
3404
3405
|
enableRetinaScaling: true
|
|
3405
3406
|
};
|
|
3406
|
-
console.debug("Capturing canvas image", options);
|
|
3407
3407
|
var base64 = this.executeWithNormalizedCanvas(function () { return _this.fabricCanvas.toDataURL(options); });
|
|
3408
3408
|
return replace(base64, /^data:.*;base64,/, "");
|
|
3409
3409
|
};
|
|
@@ -3491,7 +3491,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3491
3491
|
};
|
|
3492
3492
|
AbstractInteractiveCanvas.prototype.bindFields = function (persistedFields) {
|
|
3493
3493
|
var _this = this;
|
|
3494
|
-
console.debug("Binding fields", persistedFields);
|
|
3495
3494
|
var bound = _(persistedFields)
|
|
3496
3495
|
.flatMap(function (field) {
|
|
3497
3496
|
try {
|
|
@@ -3503,11 +3502,9 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3503
3502
|
}
|
|
3504
3503
|
})
|
|
3505
3504
|
.value();
|
|
3506
|
-
console.debug("Bound fields", bound);
|
|
3507
3505
|
this.objects$.next(bound);
|
|
3508
3506
|
};
|
|
3509
3507
|
AbstractInteractiveCanvas.prototype.bindField = function (persistedField) {
|
|
3510
|
-
console.debug("Binding field", persistedField);
|
|
3511
3508
|
var fabricObject = this.findFabricObject(persistedField.id);
|
|
3512
3509
|
switch (persistedField.type) {
|
|
3513
3510
|
case ObjectType.TEXT:
|
|
@@ -3567,7 +3564,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3567
3564
|
AbstractInteractiveCanvas.prototype.updateCanvasDimensions = function (dims, zoom) {
|
|
3568
3565
|
var width = dims.widthPx * zoom;
|
|
3569
3566
|
var height = dims.heightPx * zoom;
|
|
3570
|
-
console.debug("Updating canvas dimensions: zoom: " + zoom + ", width: " + width + ", height: " + height);
|
|
3571
3567
|
this.fabricCanvas.setZoom(zoom);
|
|
3572
3568
|
this.fabricCanvas.setDimensions({
|
|
3573
3569
|
width: width,
|
|
@@ -3577,7 +3573,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3577
3573
|
AbstractInteractiveCanvas.prototype.onProfileChanged = function (profile) {
|
|
3578
3574
|
this.setMultiSelect(profile.allowMultiSelect);
|
|
3579
3575
|
this.layoutManager$.value.onProfileChange(profile);
|
|
3580
|
-
console.debug("Canvas profile set", profile);
|
|
3581
3576
|
};
|
|
3582
3577
|
AbstractInteractiveCanvas.prototype.getFieldByCanvasObject = function (object) {
|
|
3583
3578
|
if (!object) {
|
|
@@ -3638,7 +3633,9 @@ var SelectionData = /** @class */ (function () {
|
|
|
3638
3633
|
var HeadlessInteractiveCanvas = /** @class */ (function (_super) {
|
|
3639
3634
|
__extends(HeadlessInteractiveCanvas, _super);
|
|
3640
3635
|
function HeadlessInteractiveCanvas() {
|
|
3641
|
-
|
|
3636
|
+
var _this = _super.call(this, fabric, new fabric.StaticCanvas(null, { width: 640, height: 480 }), null) || this;
|
|
3637
|
+
_this.headless = true;
|
|
3638
|
+
return _this;
|
|
3642
3639
|
}
|
|
3643
3640
|
/**
|
|
3644
3641
|
* @override
|
|
@@ -3738,6 +3735,7 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3738
3735
|
function InteractiveCanvas(elementId, devicePixelRatio) {
|
|
3739
3736
|
var _this = _super.call(this, window['fabric'], new window['fabric'].Canvas(elementId), devicePixelRatio) || this;
|
|
3740
3737
|
_this.devicePixelRatio = devicePixelRatio;
|
|
3738
|
+
_this.headless = false;
|
|
3741
3739
|
_this.undoStack = new UndoStack(_this);
|
|
3742
3740
|
//Initialize watchers
|
|
3743
3741
|
_this.fabricCanvas.on("selection:updated", function () { return _this.onFabricSelectionChanged(); });
|
|
@@ -3789,7 +3787,6 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3789
3787
|
};
|
|
3790
3788
|
InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
|
|
3791
3789
|
var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
|
|
3792
|
-
console.debug("Selection changed", selected);
|
|
3793
3790
|
this.selection$.next(new SelectionData(selected));
|
|
3794
3791
|
this.enterTextSelectionModeIfRequired();
|
|
3795
3792
|
};
|
|
@@ -25,6 +25,10 @@ import { IBackgroundImage } from "./object/impl/background-image";
|
|
|
25
25
|
* New leapfrog canvas implementation c. 2019.
|
|
26
26
|
*/
|
|
27
27
|
export interface IInteractiveCanvas {
|
|
28
|
+
/**
|
|
29
|
+
* True if the canvas is operating in a headless mode.
|
|
30
|
+
*/
|
|
31
|
+
readonly headless: boolean;
|
|
28
32
|
/**
|
|
29
33
|
* Get the canvas font library.
|
|
30
34
|
*/
|
|
@@ -2467,6 +2467,8 @@ var Text = /** @class */ (function (_super) {
|
|
|
2467
2467
|
return this.canvas.getSelection().isText && this.textSelection$.value.length > 0;
|
|
2468
2468
|
};
|
|
2469
2469
|
Text.prototype.updateTextSelection = function () {
|
|
2470
|
+
if (this.canvas.headless)
|
|
2471
|
+
return;
|
|
2470
2472
|
this.textSelection$.next(new TextSelection(this.fabricObject, this.fontLibrary));
|
|
2471
2473
|
this.notifyCanvasOfTextChanges();
|
|
2472
2474
|
};
|
|
@@ -2786,7 +2788,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2786
2788
|
*/
|
|
2787
2789
|
AbstractInteractiveCanvas.prototype.setDimensions = function (dimensions) {
|
|
2788
2790
|
if (this.dimensionsExceedRestrictions(dimensions)) {
|
|
2789
|
-
console.
|
|
2791
|
+
console.info("Requested canvas dimensions exceed current restrictions", dimensions, this.dimensionRestrictions$.value);
|
|
2790
2792
|
this.dimensionChangeRejections$.next(dimensions);
|
|
2791
2793
|
return;
|
|
2792
2794
|
}
|
|
@@ -3339,7 +3341,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3339
3341
|
return __generator(this, function (_a) {
|
|
3340
3342
|
switch (_a.label) {
|
|
3341
3343
|
case 0:
|
|
3342
|
-
console.debug("Loading canvas state", canvasState);
|
|
3343
3344
|
this.setBaseDimensions(canvasState.dimensions);
|
|
3344
3345
|
if (!(canvasState.canvasJson != undefined)) return [3 /*break*/, 2];
|
|
3345
3346
|
json_1 = JSON.parse(canvasState.canvasJson);
|
|
@@ -3403,7 +3404,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3403
3404
|
multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
|
|
3404
3405
|
enableRetinaScaling: true
|
|
3405
3406
|
};
|
|
3406
|
-
console.debug("Capturing canvas image", options);
|
|
3407
3407
|
var base64 = this.executeWithNormalizedCanvas(function () { return _this.fabricCanvas.toDataURL(options); });
|
|
3408
3408
|
return _.replace(base64, /^data:.*;base64,/, "");
|
|
3409
3409
|
};
|
|
@@ -3491,7 +3491,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3491
3491
|
};
|
|
3492
3492
|
AbstractInteractiveCanvas.prototype.bindFields = function (persistedFields) {
|
|
3493
3493
|
var _this = this;
|
|
3494
|
-
console.debug("Binding fields", persistedFields);
|
|
3495
3494
|
var bound = _(persistedFields)
|
|
3496
3495
|
.flatMap(function (field) {
|
|
3497
3496
|
try {
|
|
@@ -3503,11 +3502,9 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3503
3502
|
}
|
|
3504
3503
|
})
|
|
3505
3504
|
.value();
|
|
3506
|
-
console.debug("Bound fields", bound);
|
|
3507
3505
|
this.objects$.next(bound);
|
|
3508
3506
|
};
|
|
3509
3507
|
AbstractInteractiveCanvas.prototype.bindField = function (persistedField) {
|
|
3510
|
-
console.debug("Binding field", persistedField);
|
|
3511
3508
|
var fabricObject = this.findFabricObject(persistedField.id);
|
|
3512
3509
|
switch (persistedField.type) {
|
|
3513
3510
|
case exports.ObjectType.TEXT:
|
|
@@ -3567,7 +3564,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3567
3564
|
AbstractInteractiveCanvas.prototype.updateCanvasDimensions = function (dims, zoom) {
|
|
3568
3565
|
var width = dims.widthPx * zoom;
|
|
3569
3566
|
var height = dims.heightPx * zoom;
|
|
3570
|
-
console.debug("Updating canvas dimensions: zoom: " + zoom + ", width: " + width + ", height: " + height);
|
|
3571
3567
|
this.fabricCanvas.setZoom(zoom);
|
|
3572
3568
|
this.fabricCanvas.setDimensions({
|
|
3573
3569
|
width: width,
|
|
@@ -3577,7 +3573,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3577
3573
|
AbstractInteractiveCanvas.prototype.onProfileChanged = function (profile) {
|
|
3578
3574
|
this.setMultiSelect(profile.allowMultiSelect);
|
|
3579
3575
|
this.layoutManager$.value.onProfileChange(profile);
|
|
3580
|
-
console.debug("Canvas profile set", profile);
|
|
3581
3576
|
};
|
|
3582
3577
|
AbstractInteractiveCanvas.prototype.getFieldByCanvasObject = function (object) {
|
|
3583
3578
|
if (!object) {
|
|
@@ -3638,7 +3633,9 @@ var SelectionData = /** @class */ (function () {
|
|
|
3638
3633
|
var HeadlessInteractiveCanvas = /** @class */ (function (_super) {
|
|
3639
3634
|
__extends(HeadlessInteractiveCanvas, _super);
|
|
3640
3635
|
function HeadlessInteractiveCanvas() {
|
|
3641
|
-
|
|
3636
|
+
var _this = _super.call(this, fabric.fabric, new fabric.fabric.StaticCanvas(null, { width: 640, height: 480 }), null) || this;
|
|
3637
|
+
_this.headless = true;
|
|
3638
|
+
return _this;
|
|
3642
3639
|
}
|
|
3643
3640
|
/**
|
|
3644
3641
|
* @override
|
|
@@ -3738,6 +3735,7 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3738
3735
|
function InteractiveCanvas(elementId, devicePixelRatio) {
|
|
3739
3736
|
var _this = _super.call(this, window['fabric'], new window['fabric'].Canvas(elementId), devicePixelRatio) || this;
|
|
3740
3737
|
_this.devicePixelRatio = devicePixelRatio;
|
|
3738
|
+
_this.headless = false;
|
|
3741
3739
|
_this.undoStack = new UndoStack(_this);
|
|
3742
3740
|
//Initialize watchers
|
|
3743
3741
|
_this.fabricCanvas.on("selection:updated", function () { return _this.onFabricSelectionChanged(); });
|
|
@@ -3789,7 +3787,6 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3789
3787
|
};
|
|
3790
3788
|
InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
|
|
3791
3789
|
var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
|
|
3792
|
-
console.debug("Selection changed", selected);
|
|
3793
3790
|
this.selection$.next(new SelectionData(selected));
|
|
3794
3791
|
this.enterTextSelectionModeIfRequired();
|
|
3795
3792
|
};
|