@leapfrog/interactive-canvas 1.9.1 → 1.10.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.
@@ -22,6 +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
  import { IRichText } from "./object/impl/rich-text";
25
+ import { IBackgroundImage } from "./object/impl/background-image";
25
26
  export declare abstract class AbstractInteractiveCanvas implements IInteractiveCanvas {
26
27
  fabric: any;
27
28
  protected readonly fabricCanvas: fabric.Canvas;
@@ -219,6 +220,11 @@ export declare abstract class AbstractInteractiveCanvas implements IInteractiveC
219
220
  * @inheritDoc
220
221
  */
221
222
  addHorizontalRuleObject(): Promise<IHorizontalRule>;
223
+ /**
224
+ * @override
225
+ * @inheritDoc
226
+ */
227
+ addBackgroundImageObject(imageUrl: string): Promise<IBackgroundImage>;
222
228
  /**
223
229
  * @override
224
230
  * @inheritDoc
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export * from "./mutator/mutable-text.interface";
21
21
  export * from "./object/abstract-canvas-object";
22
22
  export * from "./object/canvas-object-data";
23
23
  export * from "./object/canvas-object.interface";
24
+ export * from "./object/impl/background-image";
24
25
  export * from "./object/impl/border";
25
26
  export * from "./object/impl/cutoff";
26
27
  export * from "./object/impl/horizontal-rule";
@@ -348,6 +348,16 @@ var LayoutManager;
348
348
  LayoutManager["ADVANCED"] = "ADVANCED";
349
349
  })(LayoutManager || (LayoutManager = {}));
350
350
 
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
+
351
361
  var AdvancedLayoutManager = /** @class */ (function (_super) {
352
362
  __extends(AdvancedLayoutManager, _super);
353
363
  function AdvancedLayoutManager(canvas) {
@@ -357,6 +367,7 @@ var AdvancedLayoutManager = /** @class */ (function (_super) {
357
367
  _this.redrawAll = new RedrawAllLayoutFunction();
358
368
  _this.repositionBorders = new RepositionBordersLayoutFunction();
359
369
  _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
370
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
360
371
  _this.resizeCanvas = new ResizeCanvasLayoutFunction();
361
372
  return _this;
362
373
  }
@@ -364,6 +375,7 @@ var AdvancedLayoutManager = /** @class */ (function (_super) {
364
375
  this.pinToBottom.execute(this.canvas);
365
376
  this.repositionCutoffs.execute(this.canvas);
366
377
  this.repositionBorders.execute(this.canvas);
378
+ this.repositionBackgrounds.execute(this.canvas);
367
379
  this.redrawAll.execute(this.canvas);
368
380
  };
369
381
  AdvancedLayoutManager.prototype.onTextChange = function () {
@@ -548,6 +560,7 @@ var StandardLayoutManager = /** @class */ (function (_super) {
548
560
  _this.redrawAll = new RedrawAllLayoutFunction();
549
561
  _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
550
562
  _this.repositionBorders = new RepositionBordersLayoutFunction();
563
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
551
564
  _this.stackObjects = new StackObjectsLayoutFunction();
552
565
  _this.updateObjectDimensions = new UpdateObjectDimensionsLayoutFunction();
553
566
  return _this;
@@ -571,6 +584,7 @@ var StandardLayoutManager = /** @class */ (function (_super) {
571
584
  StandardLayoutManager.prototype.onCanvasDimensionsChange = function () {
572
585
  this.repositionCutoffs.execute(this.canvas);
573
586
  this.repositionBorders.execute(this.canvas);
587
+ this.repositionBackgrounds.execute(this.canvas);
574
588
  };
575
589
  /**
576
590
  * @override
@@ -594,6 +608,7 @@ var StandardLayoutManager = /** @class */ (function (_super) {
594
608
  this.stackObjects.execute(this.canvas);
595
609
  this.repositionCutoffs.execute(this.canvas);
596
610
  this.repositionBorders.execute(this.canvas);
611
+ this.repositionBackgrounds.execute(this.canvas);
597
612
  this.updateObjectDimensions.execute(this.canvas);
598
613
  this.redrawAll.execute(this.canvas);
599
614
  };
@@ -1115,6 +1130,118 @@ var FieldDimensions = /** @class */ (function () {
1115
1130
  return FieldDimensions;
1116
1131
  }());
1117
1132
 
1133
+ var BackgroundImage = /** @class */ (function (_super) {
1134
+ __extends(BackgroundImage, _super);
1135
+ function BackgroundImage(canvas, fabricObject, persistedField) {
1136
+ var _this = _super.call(this, ObjectType.BACKGROUND_IMAGE, canvas, fabricObject, persistedField) || this;
1137
+ _this.imageUrl$ = new BehaviorSubject(_this.fabricObject.getSrc());
1138
+ _this.data.imagePath = _this.imageUrl$.value;
1139
+ _this.updatePosition();
1140
+ return _this;
1141
+ }
1142
+ BackgroundImage.prototype.updatePosition = function () {
1143
+ var _a = this.canvas.getDimensions(), widthPx = _a.widthPx, heightPx = _a.heightPx;
1144
+ this.fabricObject.set({
1145
+ top: 0,
1146
+ left: 0,
1147
+ scaleX: widthPx / this.fabricObject.width,
1148
+ scaleY: heightPx / this.fabricObject.height
1149
+ });
1150
+ this.fabricObject.sendToBack();
1151
+ this.updateDimensions();
1152
+ };
1153
+ /**
1154
+ * @override
1155
+ * @inheritDoc
1156
+ */
1157
+ BackgroundImage.prototype.updateFabricObjectBehavior = function () {
1158
+ _super.prototype.updateFabricObjectBehavior.call(this);
1159
+ this.fabricObject.set({
1160
+ lockMovementX: true,
1161
+ lockMovementY: true,
1162
+ lockScalingX: true,
1163
+ lockScalingY: true,
1164
+ lockScalingFlip: true
1165
+ });
1166
+ this.fabricObject.setControlsVisibility({
1167
+ tl: false,
1168
+ tr: false,
1169
+ br: false,
1170
+ bl: false,
1171
+ ml: false,
1172
+ mt: false,
1173
+ mr: false,
1174
+ mb: false,
1175
+ mtr: false
1176
+ });
1177
+ this.redraw();
1178
+ };
1179
+ /**
1180
+ * @override
1181
+ * @inheritDoc
1182
+ */
1183
+ BackgroundImage.prototype.getImageUrl = function () {
1184
+ return this.imageUrl$.value;
1185
+ };
1186
+ /**
1187
+ * @override
1188
+ * @inheritDoc
1189
+ */
1190
+ BackgroundImage.prototype.getImageUrl$ = function () {
1191
+ return this.imageUrl$;
1192
+ };
1193
+ /**
1194
+ * @override
1195
+ * @inheritDoc
1196
+ */
1197
+ BackgroundImage.prototype.setImageUrl = function (url) {
1198
+ return __awaiter(this, void 0, void 0, function () {
1199
+ return __generator(this, function (_a) {
1200
+ switch (_a.label) {
1201
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1202
+ case 1:
1203
+ _a.sent();
1204
+ this.data.imagePath = url;
1205
+ this.imageUrl$.next(url);
1206
+ this.canvas.notifyObjectListChanged();
1207
+ return [2 /*return*/];
1208
+ }
1209
+ });
1210
+ });
1211
+ };
1212
+ /**
1213
+ * @override
1214
+ * @inheritDoc
1215
+ */
1216
+ BackgroundImage.prototype.setImageWidth = function (px, sizeRestrictions) {
1217
+ return 0; //no-op
1218
+ };
1219
+ BackgroundImage.prototype.setCanvasImage = function (url) {
1220
+ return __awaiter(this, void 0, void 0, function () {
1221
+ var imageOptions, _a, widthPx, heightPx;
1222
+ var _this = this;
1223
+ return __generator(this, function (_b) {
1224
+ switch (_b.label) {
1225
+ case 0:
1226
+ imageOptions = { crossOrigin: "anonymous" };
1227
+ _a = this.canvas.getDimensions(), widthPx = _a.widthPx, heightPx = _a.heightPx;
1228
+ return [4 /*yield*/, new Promise(function (resolve) {
1229
+ _this.fabricObject.setSrc(url, function (img) {
1230
+ img.scaleToWidth(widthPx);
1231
+ img.scaleToHeight(heightPx);
1232
+ img.setCoords();
1233
+ _this.redraw();
1234
+ resolve();
1235
+ }, imageOptions);
1236
+ })];
1237
+ case 1: return [2 /*return*/, _b.sent()];
1238
+ }
1239
+ });
1240
+ });
1241
+ };
1242
+ return BackgroundImage;
1243
+ }(AbstractCanvasObject));
1244
+
1118
1245
  var Border = /** @class */ (function (_super) {
1119
1246
  __extends(Border, _super);
1120
1247
  function Border(canvas, fabricObject, persistedField) {
@@ -2517,6 +2644,7 @@ var ObjectType;
2517
2644
  ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
2518
2645
  ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
2519
2646
  ObjectType["RICH_TEXT"] = "RICH_TEXT";
2647
+ ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
2520
2648
  })(ObjectType || (ObjectType = {}));
2521
2649
 
2522
2650
  var AbstractInteractiveCanvas = /** @class */ (function () {
@@ -3066,6 +3194,37 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3066
3194
  });
3067
3195
  });
3068
3196
  };
3197
+ /**
3198
+ * @override
3199
+ * @inheritDoc
3200
+ */
3201
+ AbstractInteractiveCanvas.prototype.addBackgroundImageObject = function (imageUrl) {
3202
+ return __awaiter(this, void 0, void 0, function () {
3203
+ var options;
3204
+ var _this = this;
3205
+ return __generator(this, function (_a) {
3206
+ switch (_a.label) {
3207
+ case 0:
3208
+ options = { crossOrigin: "anonymous" };
3209
+ return [4 /*yield*/, new Promise(function (resolve) {
3210
+ _this.fabric.Image.fromURL(imageUrl, function (fabricImage) {
3211
+ var id = _this.randomId();
3212
+ fabricImage.set({
3213
+ id: id,
3214
+ });
3215
+ _this.fabricCanvas.add(fabricImage);
3216
+ var object = new BackgroundImage(_this, fabricImage);
3217
+ _this.trackNewObject(object);
3218
+ _this.selectFabricObject(fabricImage);
3219
+ _this.syncObjectList();
3220
+ resolve(object);
3221
+ }, options);
3222
+ })];
3223
+ case 1: return [2 /*return*/, _a.sent()];
3224
+ }
3225
+ });
3226
+ });
3227
+ };
3069
3228
  /**
3070
3229
  * @override
3071
3230
  * @inheritDoc
@@ -3347,6 +3506,8 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3347
3506
  return new VerticalRule(this, fabricObject, persistedField);
3348
3507
  case ObjectType.RICH_TEXT:
3349
3508
  return new RichText(this, fabricObject, persistedField);
3509
+ case ObjectType.BACKGROUND_IMAGE:
3510
+ return new BackgroundImage(this, fabricObject, persistedField);
3350
3511
  default:
3351
3512
  throw new Error("Unknown field type: [" + persistedField.type + "]");
3352
3513
  }
@@ -3502,4 +3663,4 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3502
3663
  return InteractiveCanvas;
3503
3664
  }(AbstractInteractiveCanvas));
3504
3665
 
3505
- export { AbstractCanvasObject, AbstractInteractiveCanvas, AbstractLayoutManager, AdvancedLayoutManager, 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 };
3666
+ 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 };
@@ -20,6 +20,7 @@ import { AbstractCanvasObject } from "./object/abstract-canvas-object";
20
20
  import { ObjectType } from "./types/object-type.enum";
21
21
  import { fabric } from "fabric";
22
22
  import { IRichText } from "./object/impl/rich-text";
23
+ import { IBackgroundImage } from "./object/impl/background-image";
23
24
  /**
24
25
  * New leapfrog canvas implementation c. 2019.
25
26
  */
@@ -173,6 +174,11 @@ export interface IInteractiveCanvas {
173
174
  * Add a horizontal rule object to the canvas.
174
175
  */
175
176
  addHorizontalRuleObject(): Promise<IHorizontalRule>;
177
+ /**
178
+ * Add a background image object to the canvas.
179
+ * @param imageUrl Url for image content.
180
+ */
181
+ addBackgroundImageObject(imageUrl: string): Promise<IBackgroundImage>;
176
182
  /**
177
183
  * Set the data used to prefill text into the canvas.
178
184
  * @param data Prefill data.
@@ -350,6 +350,16 @@ var ResizeCanvasLayoutFunction = /** @class */ (function () {
350
350
  LayoutManager["ADVANCED"] = "ADVANCED";
351
351
  })(exports.LayoutManager || (exports.LayoutManager = {}));
352
352
 
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
+
353
363
  var AdvancedLayoutManager = /** @class */ (function (_super) {
354
364
  __extends(AdvancedLayoutManager, _super);
355
365
  function AdvancedLayoutManager(canvas) {
@@ -359,6 +369,7 @@ var AdvancedLayoutManager = /** @class */ (function (_super) {
359
369
  _this.redrawAll = new RedrawAllLayoutFunction();
360
370
  _this.repositionBorders = new RepositionBordersLayoutFunction();
361
371
  _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
372
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
362
373
  _this.resizeCanvas = new ResizeCanvasLayoutFunction();
363
374
  return _this;
364
375
  }
@@ -366,6 +377,7 @@ var AdvancedLayoutManager = /** @class */ (function (_super) {
366
377
  this.pinToBottom.execute(this.canvas);
367
378
  this.repositionCutoffs.execute(this.canvas);
368
379
  this.repositionBorders.execute(this.canvas);
380
+ this.repositionBackgrounds.execute(this.canvas);
369
381
  this.redrawAll.execute(this.canvas);
370
382
  };
371
383
  AdvancedLayoutManager.prototype.onTextChange = function () {
@@ -550,6 +562,7 @@ var StandardLayoutManager = /** @class */ (function (_super) {
550
562
  _this.redrawAll = new RedrawAllLayoutFunction();
551
563
  _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
552
564
  _this.repositionBorders = new RepositionBordersLayoutFunction();
565
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
553
566
  _this.stackObjects = new StackObjectsLayoutFunction();
554
567
  _this.updateObjectDimensions = new UpdateObjectDimensionsLayoutFunction();
555
568
  return _this;
@@ -573,6 +586,7 @@ var StandardLayoutManager = /** @class */ (function (_super) {
573
586
  StandardLayoutManager.prototype.onCanvasDimensionsChange = function () {
574
587
  this.repositionCutoffs.execute(this.canvas);
575
588
  this.repositionBorders.execute(this.canvas);
589
+ this.repositionBackgrounds.execute(this.canvas);
576
590
  };
577
591
  /**
578
592
  * @override
@@ -596,6 +610,7 @@ var StandardLayoutManager = /** @class */ (function (_super) {
596
610
  this.stackObjects.execute(this.canvas);
597
611
  this.repositionCutoffs.execute(this.canvas);
598
612
  this.repositionBorders.execute(this.canvas);
613
+ this.repositionBackgrounds.execute(this.canvas);
599
614
  this.updateObjectDimensions.execute(this.canvas);
600
615
  this.redrawAll.execute(this.canvas);
601
616
  };
@@ -1117,6 +1132,118 @@ var FieldDimensions = /** @class */ (function () {
1117
1132
  return FieldDimensions;
1118
1133
  }());
1119
1134
 
1135
+ var BackgroundImage = /** @class */ (function (_super) {
1136
+ __extends(BackgroundImage, _super);
1137
+ function BackgroundImage(canvas, fabricObject, persistedField) {
1138
+ var _this = _super.call(this, exports.ObjectType.BACKGROUND_IMAGE, canvas, fabricObject, persistedField) || this;
1139
+ _this.imageUrl$ = new rxjs.BehaviorSubject(_this.fabricObject.getSrc());
1140
+ _this.data.imagePath = _this.imageUrl$.value;
1141
+ _this.updatePosition();
1142
+ return _this;
1143
+ }
1144
+ BackgroundImage.prototype.updatePosition = function () {
1145
+ var _a = this.canvas.getDimensions(), widthPx = _a.widthPx, heightPx = _a.heightPx;
1146
+ this.fabricObject.set({
1147
+ top: 0,
1148
+ left: 0,
1149
+ scaleX: widthPx / this.fabricObject.width,
1150
+ scaleY: heightPx / this.fabricObject.height
1151
+ });
1152
+ this.fabricObject.sendToBack();
1153
+ this.updateDimensions();
1154
+ };
1155
+ /**
1156
+ * @override
1157
+ * @inheritDoc
1158
+ */
1159
+ BackgroundImage.prototype.updateFabricObjectBehavior = function () {
1160
+ _super.prototype.updateFabricObjectBehavior.call(this);
1161
+ this.fabricObject.set({
1162
+ lockMovementX: true,
1163
+ lockMovementY: true,
1164
+ lockScalingX: true,
1165
+ lockScalingY: true,
1166
+ lockScalingFlip: true
1167
+ });
1168
+ this.fabricObject.setControlsVisibility({
1169
+ tl: false,
1170
+ tr: false,
1171
+ br: false,
1172
+ bl: false,
1173
+ ml: false,
1174
+ mt: false,
1175
+ mr: false,
1176
+ mb: false,
1177
+ mtr: false
1178
+ });
1179
+ this.redraw();
1180
+ };
1181
+ /**
1182
+ * @override
1183
+ * @inheritDoc
1184
+ */
1185
+ BackgroundImage.prototype.getImageUrl = function () {
1186
+ return this.imageUrl$.value;
1187
+ };
1188
+ /**
1189
+ * @override
1190
+ * @inheritDoc
1191
+ */
1192
+ BackgroundImage.prototype.getImageUrl$ = function () {
1193
+ return this.imageUrl$;
1194
+ };
1195
+ /**
1196
+ * @override
1197
+ * @inheritDoc
1198
+ */
1199
+ BackgroundImage.prototype.setImageUrl = function (url) {
1200
+ return __awaiter(this, void 0, void 0, function () {
1201
+ return __generator(this, function (_a) {
1202
+ switch (_a.label) {
1203
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1204
+ case 1:
1205
+ _a.sent();
1206
+ this.data.imagePath = url;
1207
+ this.imageUrl$.next(url);
1208
+ this.canvas.notifyObjectListChanged();
1209
+ return [2 /*return*/];
1210
+ }
1211
+ });
1212
+ });
1213
+ };
1214
+ /**
1215
+ * @override
1216
+ * @inheritDoc
1217
+ */
1218
+ BackgroundImage.prototype.setImageWidth = function (px, sizeRestrictions) {
1219
+ return 0; //no-op
1220
+ };
1221
+ BackgroundImage.prototype.setCanvasImage = function (url) {
1222
+ return __awaiter(this, void 0, void 0, function () {
1223
+ var imageOptions, _a, widthPx, heightPx;
1224
+ var _this = this;
1225
+ return __generator(this, function (_b) {
1226
+ switch (_b.label) {
1227
+ case 0:
1228
+ imageOptions = { crossOrigin: "anonymous" };
1229
+ _a = this.canvas.getDimensions(), widthPx = _a.widthPx, heightPx = _a.heightPx;
1230
+ return [4 /*yield*/, new Promise(function (resolve) {
1231
+ _this.fabricObject.setSrc(url, function (img) {
1232
+ img.scaleToWidth(widthPx);
1233
+ img.scaleToHeight(heightPx);
1234
+ img.setCoords();
1235
+ _this.redraw();
1236
+ resolve();
1237
+ }, imageOptions);
1238
+ })];
1239
+ case 1: return [2 /*return*/, _b.sent()];
1240
+ }
1241
+ });
1242
+ });
1243
+ };
1244
+ return BackgroundImage;
1245
+ }(AbstractCanvasObject));
1246
+
1120
1247
  var Border = /** @class */ (function (_super) {
1121
1248
  __extends(Border, _super);
1122
1249
  function Border(canvas, fabricObject, persistedField) {
@@ -2517,6 +2644,7 @@ var DefaultCanvasProfile = /** @class */ (function () {
2517
2644
  ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
2518
2645
  ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
2519
2646
  ObjectType["RICH_TEXT"] = "RICH_TEXT";
2647
+ ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
2520
2648
  })(exports.ObjectType || (exports.ObjectType = {}));
2521
2649
 
2522
2650
  var AbstractInteractiveCanvas = /** @class */ (function () {
@@ -3066,6 +3194,37 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3066
3194
  });
3067
3195
  });
3068
3196
  };
3197
+ /**
3198
+ * @override
3199
+ * @inheritDoc
3200
+ */
3201
+ AbstractInteractiveCanvas.prototype.addBackgroundImageObject = function (imageUrl) {
3202
+ return __awaiter(this, void 0, void 0, function () {
3203
+ var options;
3204
+ var _this = this;
3205
+ return __generator(this, function (_a) {
3206
+ switch (_a.label) {
3207
+ case 0:
3208
+ options = { crossOrigin: "anonymous" };
3209
+ return [4 /*yield*/, new Promise(function (resolve) {
3210
+ _this.fabric.Image.fromURL(imageUrl, function (fabricImage) {
3211
+ var id = _this.randomId();
3212
+ fabricImage.set({
3213
+ id: id,
3214
+ });
3215
+ _this.fabricCanvas.add(fabricImage);
3216
+ var object = new BackgroundImage(_this, fabricImage);
3217
+ _this.trackNewObject(object);
3218
+ _this.selectFabricObject(fabricImage);
3219
+ _this.syncObjectList();
3220
+ resolve(object);
3221
+ }, options);
3222
+ })];
3223
+ case 1: return [2 /*return*/, _a.sent()];
3224
+ }
3225
+ });
3226
+ });
3227
+ };
3069
3228
  /**
3070
3229
  * @override
3071
3230
  * @inheritDoc
@@ -3347,6 +3506,8 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3347
3506
  return new VerticalRule(this, fabricObject, persistedField);
3348
3507
  case exports.ObjectType.RICH_TEXT:
3349
3508
  return new RichText(this, fabricObject, persistedField);
3509
+ case exports.ObjectType.BACKGROUND_IMAGE:
3510
+ return new BackgroundImage(this, fabricObject, persistedField);
3350
3511
  default:
3351
3512
  throw new Error("Unknown field type: [" + persistedField.type + "]");
3352
3513
  }
@@ -3506,6 +3667,7 @@ exports.AbstractCanvasObject = AbstractCanvasObject;
3506
3667
  exports.AbstractInteractiveCanvas = AbstractInteractiveCanvas;
3507
3668
  exports.AbstractLayoutManager = AbstractLayoutManager;
3508
3669
  exports.AdvancedLayoutManager = AdvancedLayoutManager;
3670
+ exports.BackgroundImage = BackgroundImage;
3509
3671
  exports.Border = Border;
3510
3672
  exports.CanvasObjectData = CanvasObjectData;
3511
3673
  exports.Cutoff = Cutoff;
@@ -7,6 +7,7 @@ export declare class AdvancedLayoutManager extends AbstractLayoutManager {
7
7
  private redrawAll;
8
8
  private repositionBorders;
9
9
  private repositionCutoffs;
10
+ private repositionBackgrounds;
10
11
  private resizeCanvas;
11
12
  constructor(canvas: IInteractiveCanvas);
12
13
  onCanvasDimensionsChange(): void;
@@ -0,0 +1,4 @@
1
+ import { IInteractiveCanvas } from "../..";
2
+ export declare class RepositionBackgroundsLayoutFunction {
3
+ execute(canvas: IInteractiveCanvas): void;
4
+ }
@@ -8,6 +8,7 @@ export declare class StandardLayoutManager extends AbstractLayoutManager {
8
8
  private redrawAll;
9
9
  private repositionCutoffs;
10
10
  private repositionBorders;
11
+ private repositionBackgrounds;
11
12
  private stackObjects;
12
13
  private updateObjectDimensions;
13
14
  constructor(canvas: IInteractiveCanvas);
@@ -0,0 +1,38 @@
1
+ import { AbstractCanvasObject, CanvasObjectData, IDimensionRestrictions, IInteractiveCanvas, IMutableImage } from "../..";
2
+ import { ICanvasObject } from "../canvas-object.interface";
3
+ import { fabric } from "fabric";
4
+ import { Observable } from "rxjs";
5
+ export interface IBackgroundImage extends ICanvasObject, IMutableImage {
6
+ updatePosition(): void;
7
+ }
8
+ export declare class BackgroundImage extends AbstractCanvasObject<fabric.Image> implements IBackgroundImage {
9
+ private readonly imageUrl$;
10
+ constructor(canvas: IInteractiveCanvas, fabricObject: fabric.Image, persistedField?: CanvasObjectData);
11
+ updatePosition(): void;
12
+ /**
13
+ * @override
14
+ * @inheritDoc
15
+ */
16
+ protected updateFabricObjectBehavior(): void;
17
+ /**
18
+ * @override
19
+ * @inheritDoc
20
+ */
21
+ getImageUrl(): string;
22
+ /**
23
+ * @override
24
+ * @inheritDoc
25
+ */
26
+ getImageUrl$(): Observable<string>;
27
+ /**
28
+ * @override
29
+ * @inheritDoc
30
+ */
31
+ setImageUrl(url: string): Promise<void>;
32
+ /**
33
+ * @override
34
+ * @inheritDoc
35
+ */
36
+ setImageWidth(px: number, sizeRestrictions: IDimensionRestrictions): number;
37
+ private setCanvasImage;
38
+ }
@@ -7,5 +7,6 @@ export declare enum ObjectType {
7
7
  CUTOFF = "CUTOFF",
8
8
  VERTICAL_RULE = "VERTICAL_RULE",
9
9
  HORIZONTAL_RULE = "HORIZONTAL_RULE",
10
- RICH_TEXT = "RICH_TEXT"
10
+ RICH_TEXT = "RICH_TEXT",
11
+ BACKGROUND_IMAGE = "BACKGROUND_IMAGE"
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"