@leapfrog/interactive-canvas 2.0.25-beta-13 → 2.0.25-beta-14

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.
@@ -252,38 +252,6 @@ class RepositionBackgroundsLayoutFunction {
252
252
  }
253
253
  }
254
254
 
255
- class AdvancedLayoutManager extends AbstractLayoutManager {
256
- constructor(canvas) {
257
- super(canvas);
258
- this.key = LayoutManager.ADVANCED;
259
- this.pinToBottom = new PinToBottomLayoutFunction();
260
- this.redrawAll = new RedrawAllLayoutFunction();
261
- this.repositionBorders = new RepositionBordersLayoutFunction();
262
- this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
263
- this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
264
- this.resizeCanvas = new ResizeCanvasLayoutFunction();
265
- }
266
- onCanvasDimensionsChange() {
267
- this.pinToBottom.execute(this.canvas);
268
- this.repositionCutoffs.execute(this.canvas);
269
- this.repositionBorders.execute(this.canvas);
270
- this.repositionBackgrounds.execute(this.canvas);
271
- this.redrawAll.execute(this.canvas);
272
- }
273
- onTextChange() {
274
- this.resizeCanvas.execute(this.canvas);
275
- }
276
- onObjectListChange() {
277
- this.redrawAll.execute(this.canvas);
278
- }
279
- }
280
-
281
- class UpdateObjectDimensionsLayoutFunction {
282
- execute(canvas) {
283
- canvas.getObjectsInternal().forEach((object) => object.updateDimensions());
284
- }
285
- }
286
-
287
255
  const MIN_MAGNITUDE = 1;
288
256
  class StackObjectsLayoutFunction {
289
257
  execute(canvas) {
@@ -444,6 +412,66 @@ class StackObjectsLayoutFunction {
444
412
  }
445
413
  }
446
414
 
415
+ var ObjectType;
416
+ (function (ObjectType) {
417
+ ObjectType["TEXT"] = "TEXT";
418
+ ObjectType["BORDER"] = "BORDER";
419
+ ObjectType["IMAGE"] = "IMAGE";
420
+ ObjectType["RECTANGLE"] = "RECTANGLE";
421
+ ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
422
+ ObjectType["CUTOFF"] = "CUTOFF";
423
+ ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
424
+ ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
425
+ ObjectType["RICH_TEXT"] = "RICH_TEXT";
426
+ ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
427
+ })(ObjectType || (ObjectType = {}));
428
+
429
+ class AdvancedLayoutManager extends AbstractLayoutManager {
430
+ constructor(canvas) {
431
+ super(canvas);
432
+ this.key = LayoutManager.ADVANCED;
433
+ this.pinToBottom = new PinToBottomLayoutFunction();
434
+ this.redrawAll = new RedrawAllLayoutFunction();
435
+ this.repositionBorders = new RepositionBordersLayoutFunction();
436
+ this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
437
+ this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
438
+ this.resizeCanvas = new ResizeCanvasLayoutFunction();
439
+ this.stackObjects = new StackObjectsLayoutFunction();
440
+ }
441
+ onCanvasDimensionsChange() {
442
+ this.pinToBottom.execute(this.canvas);
443
+ // this.stackObjects.execute(this.canvas);
444
+ this.dimensionChange();
445
+ this.repositionCutoffs.execute(this.canvas);
446
+ this.repositionBorders.execute(this.canvas);
447
+ this.repositionBackgrounds.execute(this.canvas);
448
+ this.redrawAll.execute(this.canvas);
449
+ }
450
+ onTextChange() {
451
+ this.resizeCanvas.execute(this.canvas);
452
+ }
453
+ onObjectListChange() {
454
+ this.redrawAll.execute(this.canvas);
455
+ }
456
+ dimensionChange() {
457
+ const canvasMargin = this.canvas.getMargin();
458
+ const canvasDimensions = this.canvas.getDimensions();
459
+ const allObjects = this.canvas.getObjectsByTypesInternal(ObjectType.TEXT, ObjectType.RICH_TEXT,
460
+ //ObjectType.IMAGE,
461
+ ObjectType.RECTANGLE, ObjectType.VERTICAL_RULE, ObjectType.HORIZONTAL_RULE);
462
+ const bodyWidth = canvasDimensions.widthPx - canvasMargin.right - canvasMargin.left;
463
+ this.canvas.redraw();
464
+ //Make one pass and set the widths of all elements. This will force objects with dynamic heights (like text) to take on their necessary height before trying to lay them out.
465
+ this.stackObjects.applyWidths(allObjects, bodyWidth);
466
+ }
467
+ }
468
+
469
+ class UpdateObjectDimensionsLayoutFunction {
470
+ execute(canvas) {
471
+ canvas.getObjectsInternal().forEach((object) => object.updateDimensions());
472
+ }
473
+ }
474
+
447
475
  class StandardLayoutManager extends AbstractLayoutManager {
448
476
  constructor(canvas) {
449
477
  super(canvas);
@@ -1763,20 +1791,6 @@ class RichText extends Image {
1763
1791
  }
1764
1792
  }
1765
1793
 
1766
- var ObjectType;
1767
- (function (ObjectType) {
1768
- ObjectType["TEXT"] = "TEXT";
1769
- ObjectType["BORDER"] = "BORDER";
1770
- ObjectType["IMAGE"] = "IMAGE";
1771
- ObjectType["RECTANGLE"] = "RECTANGLE";
1772
- ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
1773
- ObjectType["CUTOFF"] = "CUTOFF";
1774
- ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
1775
- ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
1776
- ObjectType["RICH_TEXT"] = "RICH_TEXT";
1777
- ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
1778
- })(ObjectType || (ObjectType = {}));
1779
-
1780
1794
  class Text extends AbstractCanvasObject {
1781
1795
  constructor(canvas, fabricObject, persistedField) {
1782
1796
  super(ObjectType.TEXT, canvas, fabricObject, persistedField);
@@ -3709,7 +3723,7 @@ class AbstractInteractiveCanvas {
3709
3723
  * Update the actual dimensions of the canvas by multiplying the requested dimensions by the current zoom factor.
3710
3724
  */
3711
3725
  updateCanvasDimensions(dims, zoom) {
3712
- this.fabricCanvas.getWidth();
3726
+ //const oldWidth = this.fabricCanvas.getWidth();
3713
3727
  const width = dims.widthPx * zoom;
3714
3728
  const height = dims.heightPx * zoom;
3715
3729
  this.fabricCanvas.setZoom(zoom);
@@ -3717,37 +3731,39 @@ class AbstractInteractiveCanvas {
3717
3731
  width,
3718
3732
  height
3719
3733
  });
3720
- /* if (this.layoutManager$.value instanceof AdvancedLayoutManager) {
3721
- const scaleFactor = width / oldWidth;
3722
- this.fabricCanvas.calcOffset();
3723
- const objects = this.fabricCanvas.getObjects();
3724
- objects.forEach((obj: any) => {
3725
- obj.set({
3726
- left: obj.left * scaleFactor,
3727
- });
3728
- if (obj.type === "textbox" || obj.type === "text") {
3729
- obj.set({
3730
- scaleX: 1,
3731
- scaleY: 1,
3732
- width: obj.width * scaleFactor,
3733
- });
3734
- obj.initDimensions();
3735
- } else if (obj.type === "border" || obj.type === "rect") {
3736
- obj.set({
3737
- width: obj.width * scaleFactor,
3738
- scaleX: 1,
3739
- strokeUniform: true,
3740
- strokeAlign: "inner",
3741
- });
3742
- } else {
3743
- obj.set({
3744
- scaleX: obj.scaleX * scaleFactor,
3745
- });
3746
- }
3747
- obj.setCoords();
3748
- });
3749
- this.fabricCanvas.requestRenderAll();
3750
- }*/
3734
+ /*if (this.layoutManager$.value instanceof AdvancedLayoutManager) {
3735
+ const scaleFactor = width / oldWidth;
3736
+ //this.fabricCanvas.calcOffset();
3737
+ const objects = this.fabricCanvas.getObjects();
3738
+ objects.forEach((obj: any) => {
3739
+ obj.set({ ₹
3740
+ left: obj.left * scaleFactor,
3741
+ });
3742
+ if (obj.type === "textbox" || obj.type === "text") {
3743
+ obj.set({
3744
+ scaleX: 1,
3745
+ scaleY: 1,
3746
+ // scaleX: obj.scaleX * scaleFactor,
3747
+ // scaleY: obj.scaleY * scaleFactor,
3748
+ width: obj.width * scaleFactor,
3749
+ });
3750
+ // obj.initDimensions();
3751
+ } else if (obj.type === "border" || obj.type === "rect") {
3752
+ obj.set({
3753
+ width: obj.width * scaleFactor,
3754
+ scaleX: 1,
3755
+ strokeUniform: true,
3756
+ // strokeAlign: "inner",
3757
+ });
3758
+ } else {
3759
+ obj.set({
3760
+ scaleX: obj.scaleX * scaleFactor,
3761
+ });
3762
+ }
3763
+ obj.setCoords();
3764
+ });
3765
+ this.fabricCanvas.requestRenderAll();
3766
+ }*/
3751
3767
  }
3752
3768
  onProfileChanged(profile) {
3753
3769
  this.setMultiSelect(profile.allowMultiSelect);
@@ -273,38 +273,6 @@ class RepositionBackgroundsLayoutFunction {
273
273
  }
274
274
  }
275
275
 
276
- class AdvancedLayoutManager extends AbstractLayoutManager {
277
- constructor(canvas) {
278
- super(canvas);
279
- this.key = exports.LayoutManager.ADVANCED;
280
- this.pinToBottom = new PinToBottomLayoutFunction();
281
- this.redrawAll = new RedrawAllLayoutFunction();
282
- this.repositionBorders = new RepositionBordersLayoutFunction();
283
- this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
284
- this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
285
- this.resizeCanvas = new ResizeCanvasLayoutFunction();
286
- }
287
- onCanvasDimensionsChange() {
288
- this.pinToBottom.execute(this.canvas);
289
- this.repositionCutoffs.execute(this.canvas);
290
- this.repositionBorders.execute(this.canvas);
291
- this.repositionBackgrounds.execute(this.canvas);
292
- this.redrawAll.execute(this.canvas);
293
- }
294
- onTextChange() {
295
- this.resizeCanvas.execute(this.canvas);
296
- }
297
- onObjectListChange() {
298
- this.redrawAll.execute(this.canvas);
299
- }
300
- }
301
-
302
- class UpdateObjectDimensionsLayoutFunction {
303
- execute(canvas) {
304
- canvas.getObjectsInternal().forEach((object) => object.updateDimensions());
305
- }
306
- }
307
-
308
276
  const MIN_MAGNITUDE = 1;
309
277
  class StackObjectsLayoutFunction {
310
278
  execute(canvas) {
@@ -465,6 +433,66 @@ class StackObjectsLayoutFunction {
465
433
  }
466
434
  }
467
435
 
436
+ exports.ObjectType = void 0;
437
+ (function (ObjectType) {
438
+ ObjectType["TEXT"] = "TEXT";
439
+ ObjectType["BORDER"] = "BORDER";
440
+ ObjectType["IMAGE"] = "IMAGE";
441
+ ObjectType["RECTANGLE"] = "RECTANGLE";
442
+ ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
443
+ ObjectType["CUTOFF"] = "CUTOFF";
444
+ ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
445
+ ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
446
+ ObjectType["RICH_TEXT"] = "RICH_TEXT";
447
+ ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
448
+ })(exports.ObjectType || (exports.ObjectType = {}));
449
+
450
+ class AdvancedLayoutManager extends AbstractLayoutManager {
451
+ constructor(canvas) {
452
+ super(canvas);
453
+ this.key = exports.LayoutManager.ADVANCED;
454
+ this.pinToBottom = new PinToBottomLayoutFunction();
455
+ this.redrawAll = new RedrawAllLayoutFunction();
456
+ this.repositionBorders = new RepositionBordersLayoutFunction();
457
+ this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
458
+ this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
459
+ this.resizeCanvas = new ResizeCanvasLayoutFunction();
460
+ this.stackObjects = new StackObjectsLayoutFunction();
461
+ }
462
+ onCanvasDimensionsChange() {
463
+ this.pinToBottom.execute(this.canvas);
464
+ // this.stackObjects.execute(this.canvas);
465
+ this.dimensionChange();
466
+ this.repositionCutoffs.execute(this.canvas);
467
+ this.repositionBorders.execute(this.canvas);
468
+ this.repositionBackgrounds.execute(this.canvas);
469
+ this.redrawAll.execute(this.canvas);
470
+ }
471
+ onTextChange() {
472
+ this.resizeCanvas.execute(this.canvas);
473
+ }
474
+ onObjectListChange() {
475
+ this.redrawAll.execute(this.canvas);
476
+ }
477
+ dimensionChange() {
478
+ const canvasMargin = this.canvas.getMargin();
479
+ const canvasDimensions = this.canvas.getDimensions();
480
+ const allObjects = this.canvas.getObjectsByTypesInternal(exports.ObjectType.TEXT, exports.ObjectType.RICH_TEXT,
481
+ //ObjectType.IMAGE,
482
+ exports.ObjectType.RECTANGLE, exports.ObjectType.VERTICAL_RULE, exports.ObjectType.HORIZONTAL_RULE);
483
+ const bodyWidth = canvasDimensions.widthPx - canvasMargin.right - canvasMargin.left;
484
+ this.canvas.redraw();
485
+ //Make one pass and set the widths of all elements. This will force objects with dynamic heights (like text) to take on their necessary height before trying to lay them out.
486
+ this.stackObjects.applyWidths(allObjects, bodyWidth);
487
+ }
488
+ }
489
+
490
+ class UpdateObjectDimensionsLayoutFunction {
491
+ execute(canvas) {
492
+ canvas.getObjectsInternal().forEach((object) => object.updateDimensions());
493
+ }
494
+ }
495
+
468
496
  class StandardLayoutManager extends AbstractLayoutManager {
469
497
  constructor(canvas) {
470
498
  super(canvas);
@@ -1784,20 +1812,6 @@ class RichText extends Image {
1784
1812
  }
1785
1813
  }
1786
1814
 
1787
- exports.ObjectType = void 0;
1788
- (function (ObjectType) {
1789
- ObjectType["TEXT"] = "TEXT";
1790
- ObjectType["BORDER"] = "BORDER";
1791
- ObjectType["IMAGE"] = "IMAGE";
1792
- ObjectType["RECTANGLE"] = "RECTANGLE";
1793
- ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
1794
- ObjectType["CUTOFF"] = "CUTOFF";
1795
- ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
1796
- ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
1797
- ObjectType["RICH_TEXT"] = "RICH_TEXT";
1798
- ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
1799
- })(exports.ObjectType || (exports.ObjectType = {}));
1800
-
1801
1815
  class Text extends AbstractCanvasObject {
1802
1816
  constructor(canvas, fabricObject, persistedField) {
1803
1817
  super(exports.ObjectType.TEXT, canvas, fabricObject, persistedField);
@@ -3730,7 +3744,7 @@ class AbstractInteractiveCanvas {
3730
3744
  * Update the actual dimensions of the canvas by multiplying the requested dimensions by the current zoom factor.
3731
3745
  */
3732
3746
  updateCanvasDimensions(dims, zoom) {
3733
- this.fabricCanvas.getWidth();
3747
+ //const oldWidth = this.fabricCanvas.getWidth();
3734
3748
  const width = dims.widthPx * zoom;
3735
3749
  const height = dims.heightPx * zoom;
3736
3750
  this.fabricCanvas.setZoom(zoom);
@@ -3738,37 +3752,39 @@ class AbstractInteractiveCanvas {
3738
3752
  width,
3739
3753
  height
3740
3754
  });
3741
- /* if (this.layoutManager$.value instanceof AdvancedLayoutManager) {
3742
- const scaleFactor = width / oldWidth;
3743
- this.fabricCanvas.calcOffset();
3744
- const objects = this.fabricCanvas.getObjects();
3745
- objects.forEach((obj: any) => {
3746
- obj.set({
3747
- left: obj.left * scaleFactor,
3748
- });
3749
- if (obj.type === "textbox" || obj.type === "text") {
3750
- obj.set({
3751
- scaleX: 1,
3752
- scaleY: 1,
3753
- width: obj.width * scaleFactor,
3754
- });
3755
- obj.initDimensions();
3756
- } else if (obj.type === "border" || obj.type === "rect") {
3757
- obj.set({
3758
- width: obj.width * scaleFactor,
3759
- scaleX: 1,
3760
- strokeUniform: true,
3761
- strokeAlign: "inner",
3762
- });
3763
- } else {
3764
- obj.set({
3765
- scaleX: obj.scaleX * scaleFactor,
3766
- });
3767
- }
3768
- obj.setCoords();
3769
- });
3770
- this.fabricCanvas.requestRenderAll();
3771
- }*/
3755
+ /*if (this.layoutManager$.value instanceof AdvancedLayoutManager) {
3756
+ const scaleFactor = width / oldWidth;
3757
+ //this.fabricCanvas.calcOffset();
3758
+ const objects = this.fabricCanvas.getObjects();
3759
+ objects.forEach((obj: any) => {
3760
+ obj.set({ ₹
3761
+ left: obj.left * scaleFactor,
3762
+ });
3763
+ if (obj.type === "textbox" || obj.type === "text") {
3764
+ obj.set({
3765
+ scaleX: 1,
3766
+ scaleY: 1,
3767
+ // scaleX: obj.scaleX * scaleFactor,
3768
+ // scaleY: obj.scaleY * scaleFactor,
3769
+ width: obj.width * scaleFactor,
3770
+ });
3771
+ // obj.initDimensions();
3772
+ } else if (obj.type === "border" || obj.type === "rect") {
3773
+ obj.set({
3774
+ width: obj.width * scaleFactor,
3775
+ scaleX: 1,
3776
+ strokeUniform: true,
3777
+ // strokeAlign: "inner",
3778
+ });
3779
+ } else {
3780
+ obj.set({
3781
+ scaleX: obj.scaleX * scaleFactor,
3782
+ });
3783
+ }
3784
+ obj.setCoords();
3785
+ });
3786
+ this.fabricCanvas.requestRenderAll();
3787
+ }*/
3772
3788
  }
3773
3789
  onProfileChanged(profile) {
3774
3790
  this.setMultiSelect(profile.allowMultiSelect);
@@ -9,8 +9,10 @@ export declare class AdvancedLayoutManager extends AbstractLayoutManager {
9
9
  private repositionCutoffs;
10
10
  private repositionBackgrounds;
11
11
  private resizeCanvas;
12
+ private stackObjects;
12
13
  constructor(canvas: IInteractiveCanvas);
13
14
  onCanvasDimensionsChange(): void;
14
15
  onTextChange(): void;
15
16
  onObjectListChange(): void;
17
+ private dimensionChange;
16
18
  }
@@ -1,9 +1,10 @@
1
+ import { AbstractCanvasObject } from "../..";
1
2
  import { IInteractiveCanvas } from "../../interactive-canvas.interface";
2
3
  export declare class StackObjectsLayoutFunction {
3
4
  execute(canvas: IInteractiveCanvas): void;
4
5
  private layoutFooter;
5
6
  private layoutBody;
6
- private applyWidths;
7
+ applyWidths(objects: Array<AbstractCanvasObject<any>>, layoutWidth: number): void;
7
8
  private adjustCanvasSize;
8
9
  private getRows;
9
10
  private getObjectHeight;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "2.0.25-beta-13",
3
+ "version": "2.0.25-beta-14",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"