@leapfrog/interactive-canvas 1.12.2 → 1.13.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/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 +105 -107
- package/dist/interactive-canvas.interface.d.ts +4 -0
- package/dist/interactive-canvas.js +105 -107
- 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
|
/**
|
|
@@ -284,63 +284,6 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
|
|
|
284
284
|
return RedrawAllLayoutFunction;
|
|
285
285
|
}());
|
|
286
286
|
|
|
287
|
-
var RepositionCutoffsLayoutFunction = /** @class */ (function () {
|
|
288
|
-
function RepositionCutoffsLayoutFunction() {
|
|
289
|
-
}
|
|
290
|
-
RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
|
|
291
|
-
canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
|
|
292
|
-
.forEach(function (cutoff) { return cutoff.updatePosition(); });
|
|
293
|
-
};
|
|
294
|
-
return RepositionCutoffsLayoutFunction;
|
|
295
|
-
}());
|
|
296
|
-
|
|
297
|
-
var RepositionBordersLayoutFunction = /** @class */ (function () {
|
|
298
|
-
function RepositionBordersLayoutFunction() {
|
|
299
|
-
}
|
|
300
|
-
RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
|
|
301
|
-
canvas.getObjectsByTypeInternal(ObjectType.BORDER)
|
|
302
|
-
.forEach(function (border) { return border.updatePosition(); });
|
|
303
|
-
};
|
|
304
|
-
return RepositionBordersLayoutFunction;
|
|
305
|
-
}());
|
|
306
|
-
|
|
307
|
-
var PinToBottomLayoutFunction = /** @class */ (function () {
|
|
308
|
-
function PinToBottomLayoutFunction() {
|
|
309
|
-
}
|
|
310
|
-
PinToBottomLayoutFunction.prototype.execute = function (canvas) {
|
|
311
|
-
canvas.getObjectsInternal()
|
|
312
|
-
.forEach(function (object) { return object.moveToPinnedPosition(); });
|
|
313
|
-
};
|
|
314
|
-
return PinToBottomLayoutFunction;
|
|
315
|
-
}());
|
|
316
|
-
|
|
317
|
-
var ResizeCanvasLayoutFunction = /** @class */ (function () {
|
|
318
|
-
function ResizeCanvasLayoutFunction() {
|
|
319
|
-
}
|
|
320
|
-
ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
|
|
321
|
-
if (canvas.getLayoutManager().isEnforcedPositioning)
|
|
322
|
-
return;
|
|
323
|
-
if (oc(canvas.getDimensionsRestrictions()).fixed(false))
|
|
324
|
-
return;
|
|
325
|
-
var currentDimensions = canvas.getDimensions();
|
|
326
|
-
var baseDimensions = canvas.getBaseDimensions();
|
|
327
|
-
var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
|
|
328
|
-
.filter(function (text) { return text.isResizeCanvas(); })
|
|
329
|
-
.reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
|
|
330
|
-
var increase = baseDimensions.withSize(currentDimensions.width, 0);
|
|
331
|
-
while (increase.heightPx < textHeightIncreasePx) {
|
|
332
|
-
increase = increase.withSize(increase.width, increase.height + 1);
|
|
333
|
-
}
|
|
334
|
-
var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
|
|
335
|
-
if (currentDimensions.height !== targetHeight.height) {
|
|
336
|
-
canvas.setDimensions(targetHeight);
|
|
337
|
-
}
|
|
338
|
-
canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
|
|
339
|
-
canvas.redraw();
|
|
340
|
-
};
|
|
341
|
-
return ResizeCanvasLayoutFunction;
|
|
342
|
-
}());
|
|
343
|
-
|
|
344
287
|
var LayoutManager;
|
|
345
288
|
(function (LayoutManager) {
|
|
346
289
|
LayoutManager["LEGACY"] = "LEGACY";
|
|
@@ -348,45 +291,6 @@ var LayoutManager;
|
|
|
348
291
|
LayoutManager["ADVANCED"] = "ADVANCED";
|
|
349
292
|
})(LayoutManager || (LayoutManager = {}));
|
|
350
293
|
|
|
351
|
-
var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
|
|
352
|
-
function RepositionBackgroundsLayoutFunction() {
|
|
353
|
-
}
|
|
354
|
-
RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
|
|
355
|
-
canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
|
|
356
|
-
.forEach(function (border) { return border.updatePosition(); });
|
|
357
|
-
};
|
|
358
|
-
return RepositionBackgroundsLayoutFunction;
|
|
359
|
-
}());
|
|
360
|
-
|
|
361
|
-
var AdvancedLayoutManager = /** @class */ (function (_super) {
|
|
362
|
-
__extends(AdvancedLayoutManager, _super);
|
|
363
|
-
function AdvancedLayoutManager(canvas) {
|
|
364
|
-
var _this = _super.call(this, canvas) || this;
|
|
365
|
-
_this.key = LayoutManager.ADVANCED;
|
|
366
|
-
_this.pinToBottom = new PinToBottomLayoutFunction();
|
|
367
|
-
_this.redrawAll = new RedrawAllLayoutFunction();
|
|
368
|
-
_this.repositionBorders = new RepositionBordersLayoutFunction();
|
|
369
|
-
_this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
|
|
370
|
-
_this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
|
|
371
|
-
_this.resizeCanvas = new ResizeCanvasLayoutFunction();
|
|
372
|
-
return _this;
|
|
373
|
-
}
|
|
374
|
-
AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
|
|
375
|
-
this.pinToBottom.execute(this.canvas);
|
|
376
|
-
this.repositionCutoffs.execute(this.canvas);
|
|
377
|
-
this.repositionBorders.execute(this.canvas);
|
|
378
|
-
this.repositionBackgrounds.execute(this.canvas);
|
|
379
|
-
this.redrawAll.execute(this.canvas);
|
|
380
|
-
};
|
|
381
|
-
AdvancedLayoutManager.prototype.onTextChange = function () {
|
|
382
|
-
this.resizeCanvas.execute(this.canvas);
|
|
383
|
-
};
|
|
384
|
-
AdvancedLayoutManager.prototype.onObjectListChange = function () {
|
|
385
|
-
this.redrawAll.execute(this.canvas);
|
|
386
|
-
};
|
|
387
|
-
return AdvancedLayoutManager;
|
|
388
|
-
}(AbstractLayoutManager));
|
|
389
|
-
|
|
390
294
|
var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
|
|
391
295
|
function UpdateObjectDimensionsLayoutFunction() {
|
|
392
296
|
}
|
|
@@ -550,6 +454,26 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
550
454
|
return StackObjectsLayoutFunction;
|
|
551
455
|
}());
|
|
552
456
|
|
|
457
|
+
var RepositionBordersLayoutFunction = /** @class */ (function () {
|
|
458
|
+
function RepositionBordersLayoutFunction() {
|
|
459
|
+
}
|
|
460
|
+
RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
|
|
461
|
+
canvas.getObjectsByTypeInternal(ObjectType.BORDER)
|
|
462
|
+
.forEach(function (border) { return border.updatePosition(); });
|
|
463
|
+
};
|
|
464
|
+
return RepositionBordersLayoutFunction;
|
|
465
|
+
}());
|
|
466
|
+
|
|
467
|
+
var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
|
|
468
|
+
function RepositionBackgroundsLayoutFunction() {
|
|
469
|
+
}
|
|
470
|
+
RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
|
|
471
|
+
canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
|
|
472
|
+
.forEach(function (border) { return border.updatePosition(); });
|
|
473
|
+
};
|
|
474
|
+
return RepositionBackgroundsLayoutFunction;
|
|
475
|
+
}());
|
|
476
|
+
|
|
553
477
|
var StandardLayoutManager = /** @class */ (function (_super) {
|
|
554
478
|
__extends(StandardLayoutManager, _super);
|
|
555
479
|
function StandardLayoutManager(canvas) {
|
|
@@ -2465,6 +2389,8 @@ var Text = /** @class */ (function (_super) {
|
|
|
2465
2389
|
return this.canvas.getSelection().isText && this.textSelection$.value.length > 0;
|
|
2466
2390
|
};
|
|
2467
2391
|
Text.prototype.updateTextSelection = function () {
|
|
2392
|
+
if (this.canvas.headless)
|
|
2393
|
+
return;
|
|
2468
2394
|
this.textSelection$.next(new TextSelection(this.fabricObject, this.fontLibrary));
|
|
2469
2395
|
this.notifyCanvasOfTextChanges();
|
|
2470
2396
|
};
|
|
@@ -2786,7 +2712,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2786
2712
|
*/
|
|
2787
2713
|
AbstractInteractiveCanvas.prototype.setDimensions = function (dimensions) {
|
|
2788
2714
|
if (this.dimensionsExceedRestrictions(dimensions)) {
|
|
2789
|
-
console.
|
|
2715
|
+
console.info("Requested canvas dimensions exceed current restrictions", dimensions, this.dimensionRestrictions$.value);
|
|
2790
2716
|
this.dimensionChangeRejections$.next(dimensions);
|
|
2791
2717
|
return;
|
|
2792
2718
|
}
|
|
@@ -3045,7 +2971,8 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3045
2971
|
var object = new RichText(_this, fabricImage);
|
|
3046
2972
|
object.htmlContent = htmlContent;
|
|
3047
2973
|
_this.trackNewObject(object);
|
|
3048
|
-
|
|
2974
|
+
var margin = _this.getMargin();
|
|
2975
|
+
object.setImageWidth(_this.dimensions$.value.widthPx - margin.left - margin.right);
|
|
3049
2976
|
_this.selectFabricObject(fabricImage);
|
|
3050
2977
|
_this.syncObjectList();
|
|
3051
2978
|
resolve(object);
|
|
@@ -3339,7 +3266,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3339
3266
|
return __generator(this, function (_a) {
|
|
3340
3267
|
switch (_a.label) {
|
|
3341
3268
|
case 0:
|
|
3342
|
-
console.debug("Loading canvas state", canvasState);
|
|
3343
3269
|
this.setBaseDimensions(canvasState.dimensions);
|
|
3344
3270
|
if (!(canvasState.canvasJson != undefined)) return [3 /*break*/, 2];
|
|
3345
3271
|
json_1 = JSON.parse(canvasState.canvasJson);
|
|
@@ -3403,7 +3329,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3403
3329
|
multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
|
|
3404
3330
|
enableRetinaScaling: true
|
|
3405
3331
|
};
|
|
3406
|
-
console.debug("Capturing canvas image", options);
|
|
3407
3332
|
var base64 = this.executeWithNormalizedCanvas(function () { return _this.fabricCanvas.toDataURL(options); });
|
|
3408
3333
|
return replace(base64, /^data:.*;base64,/, "");
|
|
3409
3334
|
};
|
|
@@ -3491,7 +3416,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3491
3416
|
};
|
|
3492
3417
|
AbstractInteractiveCanvas.prototype.bindFields = function (persistedFields) {
|
|
3493
3418
|
var _this = this;
|
|
3494
|
-
console.debug("Binding fields", persistedFields);
|
|
3495
3419
|
var bound = _(persistedFields)
|
|
3496
3420
|
.flatMap(function (field) {
|
|
3497
3421
|
try {
|
|
@@ -3503,11 +3427,9 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3503
3427
|
}
|
|
3504
3428
|
})
|
|
3505
3429
|
.value();
|
|
3506
|
-
console.debug("Bound fields", bound);
|
|
3507
3430
|
this.objects$.next(bound);
|
|
3508
3431
|
};
|
|
3509
3432
|
AbstractInteractiveCanvas.prototype.bindField = function (persistedField) {
|
|
3510
|
-
console.debug("Binding field", persistedField);
|
|
3511
3433
|
var fabricObject = this.findFabricObject(persistedField.id);
|
|
3512
3434
|
switch (persistedField.type) {
|
|
3513
3435
|
case ObjectType.TEXT:
|
|
@@ -3567,7 +3489,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3567
3489
|
AbstractInteractiveCanvas.prototype.updateCanvasDimensions = function (dims, zoom) {
|
|
3568
3490
|
var width = dims.widthPx * zoom;
|
|
3569
3491
|
var height = dims.heightPx * zoom;
|
|
3570
|
-
console.debug("Updating canvas dimensions: zoom: " + zoom + ", width: " + width + ", height: " + height);
|
|
3571
3492
|
this.fabricCanvas.setZoom(zoom);
|
|
3572
3493
|
this.fabricCanvas.setDimensions({
|
|
3573
3494
|
width: width,
|
|
@@ -3577,7 +3498,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3577
3498
|
AbstractInteractiveCanvas.prototype.onProfileChanged = function (profile) {
|
|
3578
3499
|
this.setMultiSelect(profile.allowMultiSelect);
|
|
3579
3500
|
this.layoutManager$.value.onProfileChange(profile);
|
|
3580
|
-
console.debug("Canvas profile set", profile);
|
|
3581
3501
|
};
|
|
3582
3502
|
AbstractInteractiveCanvas.prototype.getFieldByCanvasObject = function (object) {
|
|
3583
3503
|
if (!object) {
|
|
@@ -3638,7 +3558,9 @@ var SelectionData = /** @class */ (function () {
|
|
|
3638
3558
|
var HeadlessInteractiveCanvas = /** @class */ (function (_super) {
|
|
3639
3559
|
__extends(HeadlessInteractiveCanvas, _super);
|
|
3640
3560
|
function HeadlessInteractiveCanvas() {
|
|
3641
|
-
|
|
3561
|
+
var _this = _super.call(this, fabric, new fabric.StaticCanvas(null, { width: 640, height: 480 }), null) || this;
|
|
3562
|
+
_this.headless = true;
|
|
3563
|
+
return _this;
|
|
3642
3564
|
}
|
|
3643
3565
|
/**
|
|
3644
3566
|
* @override
|
|
@@ -3738,6 +3660,7 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3738
3660
|
function InteractiveCanvas(elementId, devicePixelRatio) {
|
|
3739
3661
|
var _this = _super.call(this, window['fabric'], new window['fabric'].Canvas(elementId), devicePixelRatio) || this;
|
|
3740
3662
|
_this.devicePixelRatio = devicePixelRatio;
|
|
3663
|
+
_this.headless = false;
|
|
3741
3664
|
_this.undoStack = new UndoStack(_this);
|
|
3742
3665
|
//Initialize watchers
|
|
3743
3666
|
_this.fabricCanvas.on("selection:updated", function () { return _this.onFabricSelectionChanged(); });
|
|
@@ -3789,7 +3712,6 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3789
3712
|
};
|
|
3790
3713
|
InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
|
|
3791
3714
|
var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
|
|
3792
|
-
console.debug("Selection changed", selected);
|
|
3793
3715
|
this.selection$.next(new SelectionData(selected));
|
|
3794
3716
|
this.enterTextSelectionModeIfRequired();
|
|
3795
3717
|
};
|
|
@@ -3808,4 +3730,80 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3808
3730
|
return InteractiveCanvas;
|
|
3809
3731
|
}(AbstractInteractiveCanvas));
|
|
3810
3732
|
|
|
3733
|
+
var RepositionCutoffsLayoutFunction = /** @class */ (function () {
|
|
3734
|
+
function RepositionCutoffsLayoutFunction() {
|
|
3735
|
+
}
|
|
3736
|
+
RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
|
|
3737
|
+
canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
|
|
3738
|
+
.forEach(function (cutoff) { return cutoff.updatePosition(); });
|
|
3739
|
+
};
|
|
3740
|
+
return RepositionCutoffsLayoutFunction;
|
|
3741
|
+
}());
|
|
3742
|
+
|
|
3743
|
+
var PinToBottomLayoutFunction = /** @class */ (function () {
|
|
3744
|
+
function PinToBottomLayoutFunction() {
|
|
3745
|
+
}
|
|
3746
|
+
PinToBottomLayoutFunction.prototype.execute = function (canvas) {
|
|
3747
|
+
canvas.getObjectsInternal()
|
|
3748
|
+
.forEach(function (object) { return object.moveToPinnedPosition(); });
|
|
3749
|
+
};
|
|
3750
|
+
return PinToBottomLayoutFunction;
|
|
3751
|
+
}());
|
|
3752
|
+
|
|
3753
|
+
var ResizeCanvasLayoutFunction = /** @class */ (function () {
|
|
3754
|
+
function ResizeCanvasLayoutFunction() {
|
|
3755
|
+
}
|
|
3756
|
+
ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
|
|
3757
|
+
if (canvas.getLayoutManager().isEnforcedPositioning)
|
|
3758
|
+
return;
|
|
3759
|
+
if (oc(canvas.getDimensionsRestrictions()).fixed(false))
|
|
3760
|
+
return;
|
|
3761
|
+
var currentDimensions = canvas.getDimensions();
|
|
3762
|
+
var baseDimensions = canvas.getBaseDimensions();
|
|
3763
|
+
var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
|
|
3764
|
+
.filter(function (text) { return text.isResizeCanvas(); })
|
|
3765
|
+
.reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
|
|
3766
|
+
var increase = baseDimensions.withSize(currentDimensions.width, 0);
|
|
3767
|
+
while (increase.heightPx < textHeightIncreasePx) {
|
|
3768
|
+
increase = increase.withSize(increase.width, increase.height + 1);
|
|
3769
|
+
}
|
|
3770
|
+
var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
|
|
3771
|
+
if (currentDimensions.height !== targetHeight.height) {
|
|
3772
|
+
canvas.setDimensions(targetHeight);
|
|
3773
|
+
}
|
|
3774
|
+
canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
|
|
3775
|
+
canvas.redraw();
|
|
3776
|
+
};
|
|
3777
|
+
return ResizeCanvasLayoutFunction;
|
|
3778
|
+
}());
|
|
3779
|
+
|
|
3780
|
+
var AdvancedLayoutManager = /** @class */ (function (_super) {
|
|
3781
|
+
__extends(AdvancedLayoutManager, _super);
|
|
3782
|
+
function AdvancedLayoutManager(canvas) {
|
|
3783
|
+
var _this = _super.call(this, canvas) || this;
|
|
3784
|
+
_this.key = LayoutManager.ADVANCED;
|
|
3785
|
+
_this.pinToBottom = new PinToBottomLayoutFunction();
|
|
3786
|
+
_this.redrawAll = new RedrawAllLayoutFunction();
|
|
3787
|
+
_this.repositionBorders = new RepositionBordersLayoutFunction();
|
|
3788
|
+
_this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
|
|
3789
|
+
_this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
|
|
3790
|
+
_this.resizeCanvas = new ResizeCanvasLayoutFunction();
|
|
3791
|
+
return _this;
|
|
3792
|
+
}
|
|
3793
|
+
AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
|
|
3794
|
+
this.pinToBottom.execute(this.canvas);
|
|
3795
|
+
this.repositionCutoffs.execute(this.canvas);
|
|
3796
|
+
this.repositionBorders.execute(this.canvas);
|
|
3797
|
+
this.repositionBackgrounds.execute(this.canvas);
|
|
3798
|
+
this.redrawAll.execute(this.canvas);
|
|
3799
|
+
};
|
|
3800
|
+
AdvancedLayoutManager.prototype.onTextChange = function () {
|
|
3801
|
+
this.resizeCanvas.execute(this.canvas);
|
|
3802
|
+
};
|
|
3803
|
+
AdvancedLayoutManager.prototype.onObjectListChange = function () {
|
|
3804
|
+
this.redrawAll.execute(this.canvas);
|
|
3805
|
+
};
|
|
3806
|
+
return AdvancedLayoutManager;
|
|
3807
|
+
}(AbstractLayoutManager));
|
|
3808
|
+
|
|
3811
3809
|
export { AbstractCanvasObject, AbstractInteractiveCanvas, AbstractLayoutManager, AdvancedLayoutManager, BackgroundImage, 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 };
|
|
@@ -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
|
*/
|
|
@@ -287,108 +287,12 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
|
|
|
287
287
|
return RedrawAllLayoutFunction;
|
|
288
288
|
}());
|
|
289
289
|
|
|
290
|
-
var RepositionCutoffsLayoutFunction = /** @class */ (function () {
|
|
291
|
-
function RepositionCutoffsLayoutFunction() {
|
|
292
|
-
}
|
|
293
|
-
RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
|
|
294
|
-
canvas.getObjectsByTypeInternal(exports.ObjectType.CUTOFF)
|
|
295
|
-
.forEach(function (cutoff) { return cutoff.updatePosition(); });
|
|
296
|
-
};
|
|
297
|
-
return RepositionCutoffsLayoutFunction;
|
|
298
|
-
}());
|
|
299
|
-
|
|
300
|
-
var RepositionBordersLayoutFunction = /** @class */ (function () {
|
|
301
|
-
function RepositionBordersLayoutFunction() {
|
|
302
|
-
}
|
|
303
|
-
RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
|
|
304
|
-
canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
|
|
305
|
-
.forEach(function (border) { return border.updatePosition(); });
|
|
306
|
-
};
|
|
307
|
-
return RepositionBordersLayoutFunction;
|
|
308
|
-
}());
|
|
309
|
-
|
|
310
|
-
var PinToBottomLayoutFunction = /** @class */ (function () {
|
|
311
|
-
function PinToBottomLayoutFunction() {
|
|
312
|
-
}
|
|
313
|
-
PinToBottomLayoutFunction.prototype.execute = function (canvas) {
|
|
314
|
-
canvas.getObjectsInternal()
|
|
315
|
-
.forEach(function (object) { return object.moveToPinnedPosition(); });
|
|
316
|
-
};
|
|
317
|
-
return PinToBottomLayoutFunction;
|
|
318
|
-
}());
|
|
319
|
-
|
|
320
|
-
var ResizeCanvasLayoutFunction = /** @class */ (function () {
|
|
321
|
-
function ResizeCanvasLayoutFunction() {
|
|
322
|
-
}
|
|
323
|
-
ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
|
|
324
|
-
if (canvas.getLayoutManager().isEnforcedPositioning)
|
|
325
|
-
return;
|
|
326
|
-
if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
|
|
327
|
-
return;
|
|
328
|
-
var currentDimensions = canvas.getDimensions();
|
|
329
|
-
var baseDimensions = canvas.getBaseDimensions();
|
|
330
|
-
var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
|
|
331
|
-
.filter(function (text) { return text.isResizeCanvas(); })
|
|
332
|
-
.reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
|
|
333
|
-
var increase = baseDimensions.withSize(currentDimensions.width, 0);
|
|
334
|
-
while (increase.heightPx < textHeightIncreasePx) {
|
|
335
|
-
increase = increase.withSize(increase.width, increase.height + 1);
|
|
336
|
-
}
|
|
337
|
-
var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
|
|
338
|
-
if (currentDimensions.height !== targetHeight.height) {
|
|
339
|
-
canvas.setDimensions(targetHeight);
|
|
340
|
-
}
|
|
341
|
-
canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
|
|
342
|
-
canvas.redraw();
|
|
343
|
-
};
|
|
344
|
-
return ResizeCanvasLayoutFunction;
|
|
345
|
-
}());
|
|
346
|
-
|
|
347
290
|
(function (LayoutManager) {
|
|
348
291
|
LayoutManager["LEGACY"] = "LEGACY";
|
|
349
292
|
LayoutManager["STANDARD"] = "STANDARD";
|
|
350
293
|
LayoutManager["ADVANCED"] = "ADVANCED";
|
|
351
294
|
})(exports.LayoutManager || (exports.LayoutManager = {}));
|
|
352
295
|
|
|
353
|
-
var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
|
|
354
|
-
function RepositionBackgroundsLayoutFunction() {
|
|
355
|
-
}
|
|
356
|
-
RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
|
|
357
|
-
canvas.getObjectsByTypeInternal(exports.ObjectType.BACKGROUND_IMAGE)
|
|
358
|
-
.forEach(function (border) { return border.updatePosition(); });
|
|
359
|
-
};
|
|
360
|
-
return RepositionBackgroundsLayoutFunction;
|
|
361
|
-
}());
|
|
362
|
-
|
|
363
|
-
var AdvancedLayoutManager = /** @class */ (function (_super) {
|
|
364
|
-
__extends(AdvancedLayoutManager, _super);
|
|
365
|
-
function AdvancedLayoutManager(canvas) {
|
|
366
|
-
var _this = _super.call(this, canvas) || this;
|
|
367
|
-
_this.key = exports.LayoutManager.ADVANCED;
|
|
368
|
-
_this.pinToBottom = new PinToBottomLayoutFunction();
|
|
369
|
-
_this.redrawAll = new RedrawAllLayoutFunction();
|
|
370
|
-
_this.repositionBorders = new RepositionBordersLayoutFunction();
|
|
371
|
-
_this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
|
|
372
|
-
_this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
|
|
373
|
-
_this.resizeCanvas = new ResizeCanvasLayoutFunction();
|
|
374
|
-
return _this;
|
|
375
|
-
}
|
|
376
|
-
AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
|
|
377
|
-
this.pinToBottom.execute(this.canvas);
|
|
378
|
-
this.repositionCutoffs.execute(this.canvas);
|
|
379
|
-
this.repositionBorders.execute(this.canvas);
|
|
380
|
-
this.repositionBackgrounds.execute(this.canvas);
|
|
381
|
-
this.redrawAll.execute(this.canvas);
|
|
382
|
-
};
|
|
383
|
-
AdvancedLayoutManager.prototype.onTextChange = function () {
|
|
384
|
-
this.resizeCanvas.execute(this.canvas);
|
|
385
|
-
};
|
|
386
|
-
AdvancedLayoutManager.prototype.onObjectListChange = function () {
|
|
387
|
-
this.redrawAll.execute(this.canvas);
|
|
388
|
-
};
|
|
389
|
-
return AdvancedLayoutManager;
|
|
390
|
-
}(AbstractLayoutManager));
|
|
391
|
-
|
|
392
296
|
var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
|
|
393
297
|
function UpdateObjectDimensionsLayoutFunction() {
|
|
394
298
|
}
|
|
@@ -552,6 +456,26 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
|
|
|
552
456
|
return StackObjectsLayoutFunction;
|
|
553
457
|
}());
|
|
554
458
|
|
|
459
|
+
var RepositionBordersLayoutFunction = /** @class */ (function () {
|
|
460
|
+
function RepositionBordersLayoutFunction() {
|
|
461
|
+
}
|
|
462
|
+
RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
|
|
463
|
+
canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
|
|
464
|
+
.forEach(function (border) { return border.updatePosition(); });
|
|
465
|
+
};
|
|
466
|
+
return RepositionBordersLayoutFunction;
|
|
467
|
+
}());
|
|
468
|
+
|
|
469
|
+
var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
|
|
470
|
+
function RepositionBackgroundsLayoutFunction() {
|
|
471
|
+
}
|
|
472
|
+
RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
|
|
473
|
+
canvas.getObjectsByTypeInternal(exports.ObjectType.BACKGROUND_IMAGE)
|
|
474
|
+
.forEach(function (border) { return border.updatePosition(); });
|
|
475
|
+
};
|
|
476
|
+
return RepositionBackgroundsLayoutFunction;
|
|
477
|
+
}());
|
|
478
|
+
|
|
555
479
|
var StandardLayoutManager = /** @class */ (function (_super) {
|
|
556
480
|
__extends(StandardLayoutManager, _super);
|
|
557
481
|
function StandardLayoutManager(canvas) {
|
|
@@ -2467,6 +2391,8 @@ var Text = /** @class */ (function (_super) {
|
|
|
2467
2391
|
return this.canvas.getSelection().isText && this.textSelection$.value.length > 0;
|
|
2468
2392
|
};
|
|
2469
2393
|
Text.prototype.updateTextSelection = function () {
|
|
2394
|
+
if (this.canvas.headless)
|
|
2395
|
+
return;
|
|
2470
2396
|
this.textSelection$.next(new TextSelection(this.fabricObject, this.fontLibrary));
|
|
2471
2397
|
this.notifyCanvasOfTextChanges();
|
|
2472
2398
|
};
|
|
@@ -2786,7 +2712,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
2786
2712
|
*/
|
|
2787
2713
|
AbstractInteractiveCanvas.prototype.setDimensions = function (dimensions) {
|
|
2788
2714
|
if (this.dimensionsExceedRestrictions(dimensions)) {
|
|
2789
|
-
console.
|
|
2715
|
+
console.info("Requested canvas dimensions exceed current restrictions", dimensions, this.dimensionRestrictions$.value);
|
|
2790
2716
|
this.dimensionChangeRejections$.next(dimensions);
|
|
2791
2717
|
return;
|
|
2792
2718
|
}
|
|
@@ -3045,7 +2971,8 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3045
2971
|
var object = new RichText(_this, fabricImage);
|
|
3046
2972
|
object.htmlContent = htmlContent;
|
|
3047
2973
|
_this.trackNewObject(object);
|
|
3048
|
-
|
|
2974
|
+
var margin = _this.getMargin();
|
|
2975
|
+
object.setImageWidth(_this.dimensions$.value.widthPx - margin.left - margin.right);
|
|
3049
2976
|
_this.selectFabricObject(fabricImage);
|
|
3050
2977
|
_this.syncObjectList();
|
|
3051
2978
|
resolve(object);
|
|
@@ -3339,7 +3266,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3339
3266
|
return __generator(this, function (_a) {
|
|
3340
3267
|
switch (_a.label) {
|
|
3341
3268
|
case 0:
|
|
3342
|
-
console.debug("Loading canvas state", canvasState);
|
|
3343
3269
|
this.setBaseDimensions(canvasState.dimensions);
|
|
3344
3270
|
if (!(canvasState.canvasJson != undefined)) return [3 /*break*/, 2];
|
|
3345
3271
|
json_1 = JSON.parse(canvasState.canvasJson);
|
|
@@ -3403,7 +3329,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3403
3329
|
multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
|
|
3404
3330
|
enableRetinaScaling: true
|
|
3405
3331
|
};
|
|
3406
|
-
console.debug("Capturing canvas image", options);
|
|
3407
3332
|
var base64 = this.executeWithNormalizedCanvas(function () { return _this.fabricCanvas.toDataURL(options); });
|
|
3408
3333
|
return _.replace(base64, /^data:.*;base64,/, "");
|
|
3409
3334
|
};
|
|
@@ -3491,7 +3416,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3491
3416
|
};
|
|
3492
3417
|
AbstractInteractiveCanvas.prototype.bindFields = function (persistedFields) {
|
|
3493
3418
|
var _this = this;
|
|
3494
|
-
console.debug("Binding fields", persistedFields);
|
|
3495
3419
|
var bound = _(persistedFields)
|
|
3496
3420
|
.flatMap(function (field) {
|
|
3497
3421
|
try {
|
|
@@ -3503,11 +3427,9 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3503
3427
|
}
|
|
3504
3428
|
})
|
|
3505
3429
|
.value();
|
|
3506
|
-
console.debug("Bound fields", bound);
|
|
3507
3430
|
this.objects$.next(bound);
|
|
3508
3431
|
};
|
|
3509
3432
|
AbstractInteractiveCanvas.prototype.bindField = function (persistedField) {
|
|
3510
|
-
console.debug("Binding field", persistedField);
|
|
3511
3433
|
var fabricObject = this.findFabricObject(persistedField.id);
|
|
3512
3434
|
switch (persistedField.type) {
|
|
3513
3435
|
case exports.ObjectType.TEXT:
|
|
@@ -3567,7 +3489,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3567
3489
|
AbstractInteractiveCanvas.prototype.updateCanvasDimensions = function (dims, zoom) {
|
|
3568
3490
|
var width = dims.widthPx * zoom;
|
|
3569
3491
|
var height = dims.heightPx * zoom;
|
|
3570
|
-
console.debug("Updating canvas dimensions: zoom: " + zoom + ", width: " + width + ", height: " + height);
|
|
3571
3492
|
this.fabricCanvas.setZoom(zoom);
|
|
3572
3493
|
this.fabricCanvas.setDimensions({
|
|
3573
3494
|
width: width,
|
|
@@ -3577,7 +3498,6 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
|
|
|
3577
3498
|
AbstractInteractiveCanvas.prototype.onProfileChanged = function (profile) {
|
|
3578
3499
|
this.setMultiSelect(profile.allowMultiSelect);
|
|
3579
3500
|
this.layoutManager$.value.onProfileChange(profile);
|
|
3580
|
-
console.debug("Canvas profile set", profile);
|
|
3581
3501
|
};
|
|
3582
3502
|
AbstractInteractiveCanvas.prototype.getFieldByCanvasObject = function (object) {
|
|
3583
3503
|
if (!object) {
|
|
@@ -3638,7 +3558,9 @@ var SelectionData = /** @class */ (function () {
|
|
|
3638
3558
|
var HeadlessInteractiveCanvas = /** @class */ (function (_super) {
|
|
3639
3559
|
__extends(HeadlessInteractiveCanvas, _super);
|
|
3640
3560
|
function HeadlessInteractiveCanvas() {
|
|
3641
|
-
|
|
3561
|
+
var _this = _super.call(this, fabric.fabric, new fabric.fabric.StaticCanvas(null, { width: 640, height: 480 }), null) || this;
|
|
3562
|
+
_this.headless = true;
|
|
3563
|
+
return _this;
|
|
3642
3564
|
}
|
|
3643
3565
|
/**
|
|
3644
3566
|
* @override
|
|
@@ -3738,6 +3660,7 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3738
3660
|
function InteractiveCanvas(elementId, devicePixelRatio) {
|
|
3739
3661
|
var _this = _super.call(this, window['fabric'], new window['fabric'].Canvas(elementId), devicePixelRatio) || this;
|
|
3740
3662
|
_this.devicePixelRatio = devicePixelRatio;
|
|
3663
|
+
_this.headless = false;
|
|
3741
3664
|
_this.undoStack = new UndoStack(_this);
|
|
3742
3665
|
//Initialize watchers
|
|
3743
3666
|
_this.fabricCanvas.on("selection:updated", function () { return _this.onFabricSelectionChanged(); });
|
|
@@ -3789,7 +3712,6 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3789
3712
|
};
|
|
3790
3713
|
InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
|
|
3791
3714
|
var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
|
|
3792
|
-
console.debug("Selection changed", selected);
|
|
3793
3715
|
this.selection$.next(new SelectionData(selected));
|
|
3794
3716
|
this.enterTextSelectionModeIfRequired();
|
|
3795
3717
|
};
|
|
@@ -3808,6 +3730,82 @@ var InteractiveCanvas = /** @class */ (function (_super) {
|
|
|
3808
3730
|
return InteractiveCanvas;
|
|
3809
3731
|
}(AbstractInteractiveCanvas));
|
|
3810
3732
|
|
|
3733
|
+
var RepositionCutoffsLayoutFunction = /** @class */ (function () {
|
|
3734
|
+
function RepositionCutoffsLayoutFunction() {
|
|
3735
|
+
}
|
|
3736
|
+
RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
|
|
3737
|
+
canvas.getObjectsByTypeInternal(exports.ObjectType.CUTOFF)
|
|
3738
|
+
.forEach(function (cutoff) { return cutoff.updatePosition(); });
|
|
3739
|
+
};
|
|
3740
|
+
return RepositionCutoffsLayoutFunction;
|
|
3741
|
+
}());
|
|
3742
|
+
|
|
3743
|
+
var PinToBottomLayoutFunction = /** @class */ (function () {
|
|
3744
|
+
function PinToBottomLayoutFunction() {
|
|
3745
|
+
}
|
|
3746
|
+
PinToBottomLayoutFunction.prototype.execute = function (canvas) {
|
|
3747
|
+
canvas.getObjectsInternal()
|
|
3748
|
+
.forEach(function (object) { return object.moveToPinnedPosition(); });
|
|
3749
|
+
};
|
|
3750
|
+
return PinToBottomLayoutFunction;
|
|
3751
|
+
}());
|
|
3752
|
+
|
|
3753
|
+
var ResizeCanvasLayoutFunction = /** @class */ (function () {
|
|
3754
|
+
function ResizeCanvasLayoutFunction() {
|
|
3755
|
+
}
|
|
3756
|
+
ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
|
|
3757
|
+
if (canvas.getLayoutManager().isEnforcedPositioning)
|
|
3758
|
+
return;
|
|
3759
|
+
if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
|
|
3760
|
+
return;
|
|
3761
|
+
var currentDimensions = canvas.getDimensions();
|
|
3762
|
+
var baseDimensions = canvas.getBaseDimensions();
|
|
3763
|
+
var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
|
|
3764
|
+
.filter(function (text) { return text.isResizeCanvas(); })
|
|
3765
|
+
.reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
|
|
3766
|
+
var increase = baseDimensions.withSize(currentDimensions.width, 0);
|
|
3767
|
+
while (increase.heightPx < textHeightIncreasePx) {
|
|
3768
|
+
increase = increase.withSize(increase.width, increase.height + 1);
|
|
3769
|
+
}
|
|
3770
|
+
var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
|
|
3771
|
+
if (currentDimensions.height !== targetHeight.height) {
|
|
3772
|
+
canvas.setDimensions(targetHeight);
|
|
3773
|
+
}
|
|
3774
|
+
canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
|
|
3775
|
+
canvas.redraw();
|
|
3776
|
+
};
|
|
3777
|
+
return ResizeCanvasLayoutFunction;
|
|
3778
|
+
}());
|
|
3779
|
+
|
|
3780
|
+
var AdvancedLayoutManager = /** @class */ (function (_super) {
|
|
3781
|
+
__extends(AdvancedLayoutManager, _super);
|
|
3782
|
+
function AdvancedLayoutManager(canvas) {
|
|
3783
|
+
var _this = _super.call(this, canvas) || this;
|
|
3784
|
+
_this.key = exports.LayoutManager.ADVANCED;
|
|
3785
|
+
_this.pinToBottom = new PinToBottomLayoutFunction();
|
|
3786
|
+
_this.redrawAll = new RedrawAllLayoutFunction();
|
|
3787
|
+
_this.repositionBorders = new RepositionBordersLayoutFunction();
|
|
3788
|
+
_this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
|
|
3789
|
+
_this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
|
|
3790
|
+
_this.resizeCanvas = new ResizeCanvasLayoutFunction();
|
|
3791
|
+
return _this;
|
|
3792
|
+
}
|
|
3793
|
+
AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
|
|
3794
|
+
this.pinToBottom.execute(this.canvas);
|
|
3795
|
+
this.repositionCutoffs.execute(this.canvas);
|
|
3796
|
+
this.repositionBorders.execute(this.canvas);
|
|
3797
|
+
this.repositionBackgrounds.execute(this.canvas);
|
|
3798
|
+
this.redrawAll.execute(this.canvas);
|
|
3799
|
+
};
|
|
3800
|
+
AdvancedLayoutManager.prototype.onTextChange = function () {
|
|
3801
|
+
this.resizeCanvas.execute(this.canvas);
|
|
3802
|
+
};
|
|
3803
|
+
AdvancedLayoutManager.prototype.onObjectListChange = function () {
|
|
3804
|
+
this.redrawAll.execute(this.canvas);
|
|
3805
|
+
};
|
|
3806
|
+
return AdvancedLayoutManager;
|
|
3807
|
+
}(AbstractLayoutManager));
|
|
3808
|
+
|
|
3811
3809
|
exports.AbstractCanvasObject = AbstractCanvasObject;
|
|
3812
3810
|
exports.AbstractInteractiveCanvas = AbstractInteractiveCanvas;
|
|
3813
3811
|
exports.AbstractLayoutManager = AbstractLayoutManager;
|