@leapfrog/interactive-canvas 1.0.3 → 1.0.5

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.
@@ -22,7 +22,7 @@ import { ICanvasState } from "./types/canvas-state.interface";
22
22
  import { ITextSelection } from "./mutator/mutable-text-style.interface";
23
23
  import { fabric } from "fabric";
24
24
  export declare abstract class AbstractInteractiveCanvas implements IInteractiveCanvas {
25
- protected fabric: any;
25
+ fabric: any;
26
26
  protected readonly fabricCanvas: fabric.Canvas;
27
27
  protected devicePixelRatio: number;
28
28
  protected readonly IMAGE_CAPTURE_COEFFICIENT: number;
@@ -260,6 +260,61 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
260
260
  return RedrawAllLayoutFunction;
261
261
  }());
262
262
 
263
+ var RepositionCutoffsLayoutFunction = /** @class */ (function () {
264
+ function RepositionCutoffsLayoutFunction() {
265
+ }
266
+ RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
267
+ canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
268
+ .forEach(function (cutoff) { return cutoff.updatePosition(); });
269
+ };
270
+ return RepositionCutoffsLayoutFunction;
271
+ }());
272
+
273
+ var RepositionBordersLayoutFunction = /** @class */ (function () {
274
+ function RepositionBordersLayoutFunction() {
275
+ }
276
+ RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
277
+ canvas.getObjectsByTypeInternal(ObjectType.BORDER)
278
+ .forEach(function (border) { return border.updatePosition(); });
279
+ };
280
+ return RepositionBordersLayoutFunction;
281
+ }());
282
+
283
+ var PinToBottomLayoutFunction = /** @class */ (function () {
284
+ function PinToBottomLayoutFunction() {
285
+ }
286
+ PinToBottomLayoutFunction.prototype.execute = function (canvas) {
287
+ canvas.getObjectsInternal()
288
+ .forEach(function (object) { return object.moveToPinnedPosition(); });
289
+ };
290
+ return PinToBottomLayoutFunction;
291
+ }());
292
+
293
+ var ResizeCanvasLayoutFunction = /** @class */ (function () {
294
+ function ResizeCanvasLayoutFunction() {
295
+ }
296
+ ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
297
+ if (canvas.getLayoutManager().isEnforcedPositioning)
298
+ return;
299
+ var currentDimensions = canvas.getDimensions();
300
+ var baseDimensions = canvas.getBaseDimensions();
301
+ var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
302
+ .filter(function (text) { return text.isResizeCanvas(); })
303
+ .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
304
+ var increase = baseDimensions.withSize(currentDimensions.width, 0);
305
+ while (increase.heightPx < textHeightIncreasePx) {
306
+ increase = increase.withSize(increase.width, increase.height + 1);
307
+ }
308
+ var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
309
+ if (currentDimensions.height !== targetHeight.height) {
310
+ canvas.setDimensions(targetHeight);
311
+ }
312
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
313
+ canvas.redraw();
314
+ };
315
+ return ResizeCanvasLayoutFunction;
316
+ }());
317
+
263
318
  var LayoutManager;
264
319
  (function (LayoutManager) {
265
320
  LayoutManager["LEGACY"] = "LEGACY";
@@ -267,6 +322,33 @@ var LayoutManager;
267
322
  LayoutManager["ADVANCED"] = "ADVANCED";
268
323
  })(LayoutManager || (LayoutManager = {}));
269
324
 
325
+ var AdvancedLayoutManager = /** @class */ (function (_super) {
326
+ __extends(AdvancedLayoutManager, _super);
327
+ function AdvancedLayoutManager(canvas) {
328
+ var _this = _super.call(this, canvas) || this;
329
+ _this.key = LayoutManager.ADVANCED;
330
+ _this.pinToBottom = new PinToBottomLayoutFunction();
331
+ _this.redrawAll = new RedrawAllLayoutFunction();
332
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
333
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
334
+ _this.resizeCanvas = new ResizeCanvasLayoutFunction();
335
+ return _this;
336
+ }
337
+ AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
338
+ this.pinToBottom.execute(this.canvas);
339
+ this.repositionCutoffs.execute(this.canvas);
340
+ this.repositionBorders.execute(this.canvas);
341
+ this.redrawAll.execute(this.canvas);
342
+ };
343
+ AdvancedLayoutManager.prototype.onTextChange = function () {
344
+ this.resizeCanvas.execute(this.canvas);
345
+ };
346
+ AdvancedLayoutManager.prototype.onObjectListChange = function () {
347
+ this.redrawAll.execute(this.canvas);
348
+ };
349
+ return AdvancedLayoutManager;
350
+ }(AbstractLayoutManager));
351
+
270
352
  var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
271
353
  function UpdateObjectDimensionsLayoutFunction() {
272
354
  }
@@ -428,16 +510,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
428
510
  return StackObjectsLayoutFunction;
429
511
  }());
430
512
 
431
- var RepositionBordersLayoutFunction = /** @class */ (function () {
432
- function RepositionBordersLayoutFunction() {
433
- }
434
- RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
435
- canvas.getObjectsByTypeInternal(ObjectType.BORDER)
436
- .forEach(function (border) { return border.updatePosition(); });
437
- };
438
- return RepositionBordersLayoutFunction;
439
- }());
440
-
441
513
  var StandardLayoutManager = /** @class */ (function (_super) {
442
514
  __extends(StandardLayoutManager, _super);
443
515
  function StandardLayoutManager(canvas) {
@@ -1893,8 +1965,8 @@ var Text = /** @class */ (function (_super) {
1893
1965
  if (this.data.bulleted)
1894
1966
  this.enableBullets();
1895
1967
  var originalRender = this.fabricObject["_render"];
1968
+ var fabric = this.canvas.fabric;
1896
1969
  this.fabricObject["_render"] = function (ctx) {
1897
- var _this = this;
1898
1970
  var fabricText = this;
1899
1971
  if (fabricText["_bullets"]) {
1900
1972
  // Determine list of active bullets
@@ -1925,7 +1997,7 @@ var Text = /** @class */ (function (_super) {
1925
1997
  selectable: false,
1926
1998
  excludeFromJson: true
1927
1999
  };
1928
- activeBullets_1[lineIndex] = new _this.canvas.fabric.Circle(options);
2000
+ activeBullets_1[lineIndex] = new fabric.Circle(options);
1929
2001
  }
1930
2002
  }
1931
2003
  }
@@ -2723,7 +2795,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2723
2795
  AbstractInteractiveCanvas.prototype.setPrefillData = function (data) {
2724
2796
  _(this.getObjectsByTypeInternal(ObjectType.TEXT)).each(function (object) {
2725
2797
  var prefillType = object.getPrefillType();
2726
- if (prefillType !== null) {
2798
+ if (prefillType !== undefined) {
2727
2799
  object.setText(data[prefillType] || "");
2728
2800
  }
2729
2801
  });
@@ -3150,76 +3222,4 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3150
3222
  return InteractiveCanvas;
3151
3223
  }(AbstractInteractiveCanvas));
3152
3224
 
3153
- var RepositionCutoffsLayoutFunction = /** @class */ (function () {
3154
- function RepositionCutoffsLayoutFunction() {
3155
- }
3156
- RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
3157
- canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
3158
- .forEach(function (cutoff) { return cutoff.updatePosition(); });
3159
- };
3160
- return RepositionCutoffsLayoutFunction;
3161
- }());
3162
-
3163
- var PinToBottomLayoutFunction = /** @class */ (function () {
3164
- function PinToBottomLayoutFunction() {
3165
- }
3166
- PinToBottomLayoutFunction.prototype.execute = function (canvas) {
3167
- canvas.getObjectsInternal()
3168
- .forEach(function (object) { return object.moveToPinnedPosition(); });
3169
- };
3170
- return PinToBottomLayoutFunction;
3171
- }());
3172
-
3173
- var ResizeCanvasLayoutFunction = /** @class */ (function () {
3174
- function ResizeCanvasLayoutFunction() {
3175
- }
3176
- ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
3177
- if (canvas.getLayoutManager().isEnforcedPositioning)
3178
- return;
3179
- var currentDimensions = canvas.getDimensions();
3180
- var baseDimensions = canvas.getBaseDimensions();
3181
- var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
3182
- .filter(function (text) { return text.isResizeCanvas(); })
3183
- .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
3184
- var increase = baseDimensions.withSize(currentDimensions.width, 0);
3185
- while (increase.heightPx < textHeightIncreasePx) {
3186
- increase = increase.withSize(increase.width, increase.height + 1);
3187
- }
3188
- var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
3189
- if (currentDimensions.height !== targetHeight.height) {
3190
- canvas.setDimensions(targetHeight);
3191
- }
3192
- canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
3193
- canvas.redraw();
3194
- };
3195
- return ResizeCanvasLayoutFunction;
3196
- }());
3197
-
3198
- var AdvancedLayoutManager = /** @class */ (function (_super) {
3199
- __extends(AdvancedLayoutManager, _super);
3200
- function AdvancedLayoutManager(canvas) {
3201
- var _this = _super.call(this, canvas) || this;
3202
- _this.key = LayoutManager.ADVANCED;
3203
- _this.pinToBottom = new PinToBottomLayoutFunction();
3204
- _this.redrawAll = new RedrawAllLayoutFunction();
3205
- _this.repositionBorders = new RepositionBordersLayoutFunction();
3206
- _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
3207
- _this.resizeCanvas = new ResizeCanvasLayoutFunction();
3208
- return _this;
3209
- }
3210
- AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
3211
- this.pinToBottom.execute(this.canvas);
3212
- this.repositionCutoffs.execute(this.canvas);
3213
- this.repositionBorders.execute(this.canvas);
3214
- this.redrawAll.execute(this.canvas);
3215
- };
3216
- AdvancedLayoutManager.prototype.onTextChange = function () {
3217
- this.resizeCanvas.execute(this.canvas);
3218
- };
3219
- AdvancedLayoutManager.prototype.onObjectListChange = function () {
3220
- this.redrawAll.execute(this.canvas);
3221
- };
3222
- return AdvancedLayoutManager;
3223
- }(AbstractLayoutManager));
3224
-
3225
3225
  export { AbstractCanvasObject, AbstractInteractiveCanvas, AbstractLayoutManager, AdvancedLayoutManager, Border, CanvasObjectData, Cutoff, DefaultCanvasProfile, Font, FontLibrary, HeadlessInteractiveCanvas, HorizontalRule, Image, ImageType, InteractiveCanvas, LayoutManager, ObjectType, PixelCanvasDimensions, Print6ColCanvasDimensions, Print8ColCanvasDimensions, Rectangle, SelectionData, StandardLayoutManager, Text, UNKNOWN_FONT, UnknownFont, VerticalRule, isMutableBackgroundColor, isMutableColor, isMutableImage, isMutablePosition, isMutableText, isMutableTextStyle };
@@ -263,12 +263,94 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
263
263
  return RedrawAllLayoutFunction;
264
264
  }());
265
265
 
266
+ var RepositionCutoffsLayoutFunction = /** @class */ (function () {
267
+ function RepositionCutoffsLayoutFunction() {
268
+ }
269
+ RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
270
+ canvas.getObjectsByTypeInternal(exports.ObjectType.CUTOFF)
271
+ .forEach(function (cutoff) { return cutoff.updatePosition(); });
272
+ };
273
+ return RepositionCutoffsLayoutFunction;
274
+ }());
275
+
276
+ var RepositionBordersLayoutFunction = /** @class */ (function () {
277
+ function RepositionBordersLayoutFunction() {
278
+ }
279
+ RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
280
+ canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
281
+ .forEach(function (border) { return border.updatePosition(); });
282
+ };
283
+ return RepositionBordersLayoutFunction;
284
+ }());
285
+
286
+ var PinToBottomLayoutFunction = /** @class */ (function () {
287
+ function PinToBottomLayoutFunction() {
288
+ }
289
+ PinToBottomLayoutFunction.prototype.execute = function (canvas) {
290
+ canvas.getObjectsInternal()
291
+ .forEach(function (object) { return object.moveToPinnedPosition(); });
292
+ };
293
+ return PinToBottomLayoutFunction;
294
+ }());
295
+
296
+ var ResizeCanvasLayoutFunction = /** @class */ (function () {
297
+ function ResizeCanvasLayoutFunction() {
298
+ }
299
+ ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
300
+ if (canvas.getLayoutManager().isEnforcedPositioning)
301
+ return;
302
+ var currentDimensions = canvas.getDimensions();
303
+ var baseDimensions = canvas.getBaseDimensions();
304
+ var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
305
+ .filter(function (text) { return text.isResizeCanvas(); })
306
+ .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
307
+ var increase = baseDimensions.withSize(currentDimensions.width, 0);
308
+ while (increase.heightPx < textHeightIncreasePx) {
309
+ increase = increase.withSize(increase.width, increase.height + 1);
310
+ }
311
+ var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
312
+ if (currentDimensions.height !== targetHeight.height) {
313
+ canvas.setDimensions(targetHeight);
314
+ }
315
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
316
+ canvas.redraw();
317
+ };
318
+ return ResizeCanvasLayoutFunction;
319
+ }());
320
+
266
321
  (function (LayoutManager) {
267
322
  LayoutManager["LEGACY"] = "LEGACY";
268
323
  LayoutManager["STANDARD"] = "STANDARD";
269
324
  LayoutManager["ADVANCED"] = "ADVANCED";
270
325
  })(exports.LayoutManager || (exports.LayoutManager = {}));
271
326
 
327
+ var AdvancedLayoutManager = /** @class */ (function (_super) {
328
+ __extends(AdvancedLayoutManager, _super);
329
+ function AdvancedLayoutManager(canvas) {
330
+ var _this = _super.call(this, canvas) || this;
331
+ _this.key = exports.LayoutManager.ADVANCED;
332
+ _this.pinToBottom = new PinToBottomLayoutFunction();
333
+ _this.redrawAll = new RedrawAllLayoutFunction();
334
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
335
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
336
+ _this.resizeCanvas = new ResizeCanvasLayoutFunction();
337
+ return _this;
338
+ }
339
+ AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
340
+ this.pinToBottom.execute(this.canvas);
341
+ this.repositionCutoffs.execute(this.canvas);
342
+ this.repositionBorders.execute(this.canvas);
343
+ this.redrawAll.execute(this.canvas);
344
+ };
345
+ AdvancedLayoutManager.prototype.onTextChange = function () {
346
+ this.resizeCanvas.execute(this.canvas);
347
+ };
348
+ AdvancedLayoutManager.prototype.onObjectListChange = function () {
349
+ this.redrawAll.execute(this.canvas);
350
+ };
351
+ return AdvancedLayoutManager;
352
+ }(AbstractLayoutManager));
353
+
272
354
  var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
273
355
  function UpdateObjectDimensionsLayoutFunction() {
274
356
  }
@@ -430,16 +512,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
430
512
  return StackObjectsLayoutFunction;
431
513
  }());
432
514
 
433
- var RepositionBordersLayoutFunction = /** @class */ (function () {
434
- function RepositionBordersLayoutFunction() {
435
- }
436
- RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
437
- canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
438
- .forEach(function (border) { return border.updatePosition(); });
439
- };
440
- return RepositionBordersLayoutFunction;
441
- }());
442
-
443
515
  var StandardLayoutManager = /** @class */ (function (_super) {
444
516
  __extends(StandardLayoutManager, _super);
445
517
  function StandardLayoutManager(canvas) {
@@ -1895,8 +1967,8 @@ var Text = /** @class */ (function (_super) {
1895
1967
  if (this.data.bulleted)
1896
1968
  this.enableBullets();
1897
1969
  var originalRender = this.fabricObject["_render"];
1970
+ var fabric = this.canvas.fabric;
1898
1971
  this.fabricObject["_render"] = function (ctx) {
1899
- var _this = this;
1900
1972
  var fabricText = this;
1901
1973
  if (fabricText["_bullets"]) {
1902
1974
  // Determine list of active bullets
@@ -1927,7 +1999,7 @@ var Text = /** @class */ (function (_super) {
1927
1999
  selectable: false,
1928
2000
  excludeFromJson: true
1929
2001
  };
1930
- activeBullets_1[lineIndex] = new _this.canvas.fabric.Circle(options);
2002
+ activeBullets_1[lineIndex] = new fabric.Circle(options);
1931
2003
  }
1932
2004
  }
1933
2005
  }
@@ -2723,7 +2795,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2723
2795
  AbstractInteractiveCanvas.prototype.setPrefillData = function (data) {
2724
2796
  _(this.getObjectsByTypeInternal(exports.ObjectType.TEXT)).each(function (object) {
2725
2797
  var prefillType = object.getPrefillType();
2726
- if (prefillType !== null) {
2798
+ if (prefillType !== undefined) {
2727
2799
  object.setText(data[prefillType] || "");
2728
2800
  }
2729
2801
  });
@@ -3150,78 +3222,6 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3150
3222
  return InteractiveCanvas;
3151
3223
  }(AbstractInteractiveCanvas));
3152
3224
 
3153
- var RepositionCutoffsLayoutFunction = /** @class */ (function () {
3154
- function RepositionCutoffsLayoutFunction() {
3155
- }
3156
- RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
3157
- canvas.getObjectsByTypeInternal(exports.ObjectType.CUTOFF)
3158
- .forEach(function (cutoff) { return cutoff.updatePosition(); });
3159
- };
3160
- return RepositionCutoffsLayoutFunction;
3161
- }());
3162
-
3163
- var PinToBottomLayoutFunction = /** @class */ (function () {
3164
- function PinToBottomLayoutFunction() {
3165
- }
3166
- PinToBottomLayoutFunction.prototype.execute = function (canvas) {
3167
- canvas.getObjectsInternal()
3168
- .forEach(function (object) { return object.moveToPinnedPosition(); });
3169
- };
3170
- return PinToBottomLayoutFunction;
3171
- }());
3172
-
3173
- var ResizeCanvasLayoutFunction = /** @class */ (function () {
3174
- function ResizeCanvasLayoutFunction() {
3175
- }
3176
- ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
3177
- if (canvas.getLayoutManager().isEnforcedPositioning)
3178
- return;
3179
- var currentDimensions = canvas.getDimensions();
3180
- var baseDimensions = canvas.getBaseDimensions();
3181
- var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
3182
- .filter(function (text) { return text.isResizeCanvas(); })
3183
- .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
3184
- var increase = baseDimensions.withSize(currentDimensions.width, 0);
3185
- while (increase.heightPx < textHeightIncreasePx) {
3186
- increase = increase.withSize(increase.width, increase.height + 1);
3187
- }
3188
- var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
3189
- if (currentDimensions.height !== targetHeight.height) {
3190
- canvas.setDimensions(targetHeight);
3191
- }
3192
- canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
3193
- canvas.redraw();
3194
- };
3195
- return ResizeCanvasLayoutFunction;
3196
- }());
3197
-
3198
- var AdvancedLayoutManager = /** @class */ (function (_super) {
3199
- __extends(AdvancedLayoutManager, _super);
3200
- function AdvancedLayoutManager(canvas) {
3201
- var _this = _super.call(this, canvas) || this;
3202
- _this.key = exports.LayoutManager.ADVANCED;
3203
- _this.pinToBottom = new PinToBottomLayoutFunction();
3204
- _this.redrawAll = new RedrawAllLayoutFunction();
3205
- _this.repositionBorders = new RepositionBordersLayoutFunction();
3206
- _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
3207
- _this.resizeCanvas = new ResizeCanvasLayoutFunction();
3208
- return _this;
3209
- }
3210
- AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
3211
- this.pinToBottom.execute(this.canvas);
3212
- this.repositionCutoffs.execute(this.canvas);
3213
- this.repositionBorders.execute(this.canvas);
3214
- this.redrawAll.execute(this.canvas);
3215
- };
3216
- AdvancedLayoutManager.prototype.onTextChange = function () {
3217
- this.resizeCanvas.execute(this.canvas);
3218
- };
3219
- AdvancedLayoutManager.prototype.onObjectListChange = function () {
3220
- this.redrawAll.execute(this.canvas);
3221
- };
3222
- return AdvancedLayoutManager;
3223
- }(AbstractLayoutManager));
3224
-
3225
3225
  exports.AbstractCanvasObject = AbstractCanvasObject;
3226
3226
  exports.AbstractInteractiveCanvas = AbstractInteractiveCanvas;
3227
3227
  exports.AbstractLayoutManager = AbstractLayoutManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"