@leapfrog/interactive-canvas 2.0.18 → 2.0.19

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.
@@ -3,30 +3,33 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
- var tsOptchain = require('ts-optchain');
7
6
  var rxjs = require('rxjs');
8
7
  var fabric = require('fabric');
9
8
 
10
- var PIXELS_PER_MM = 3.937;
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
12
+
13
+ var PIXELS_PER_MM$2 = 3.937;
11
14
  var MillimeterDimensions = /** @class */ (function () {
12
15
  function MillimeterDimensions(width, height) {
13
16
  this.widthUnit = "mm";
14
17
  this.heightUnit = "mm";
15
18
  this.width = width;
16
19
  this.widthMm = Math.max(0, width);
17
- this.widthPx = _.round(this.widthMm * PIXELS_PER_MM);
20
+ this.widthPx = _.round(this.widthMm * PIXELS_PER_MM$2);
18
21
  this.height = height;
19
22
  this.heightMm = Math.max(0, height);
20
- this.heightPx = _.round(this.heightMm * PIXELS_PER_MM);
23
+ this.heightPx = _.round(this.heightMm * PIXELS_PER_MM$2);
21
24
  }
22
25
  MillimeterDimensions.prototype.withSize = function (width, height) {
23
26
  return new MillimeterDimensions(width, height);
24
27
  };
25
28
  MillimeterDimensions.prototype.widthPxToMm = function (px) {
26
- return px / PIXELS_PER_MM;
29
+ return px / PIXELS_PER_MM$2;
27
30
  };
28
31
  MillimeterDimensions.prototype.heightPxToMm = function (px) {
29
- return px / PIXELS_PER_MM;
32
+ return px / PIXELS_PER_MM$2;
30
33
  };
31
34
  return MillimeterDimensions;
32
35
  }());
@@ -52,8 +55,8 @@ var PixelCanvasDimensions = /** @class */ (function () {
52
55
  return PixelCanvasDimensions;
53
56
  }());
54
57
 
55
- var COLUMN_WIDTH_MM = 41;
56
- var GUTTER_WIDTH_MM = 3;
58
+ var COLUMN_WIDTH_MM$1 = 41;
59
+ var GUTTER_WIDTH_MM$1 = 3;
57
60
  var PIXELS_PER_MM$1 = 3.937;
58
61
  var Print6ColCanvasDimensions = /** @class */ (function () {
59
62
  function Print6ColCanvasDimensions(width, height) {
@@ -61,8 +64,8 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
61
64
  this.heightUnit = "cm";
62
65
  this.width = width;
63
66
  this.gutterCount = Math.max(0, width - 1);
64
- this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
65
- this.columnsTotalMm = width * COLUMN_WIDTH_MM;
67
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
68
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
66
69
  this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
67
70
  this.widthPx = _.round(this.widthMm * PIXELS_PER_MM$1);
68
71
  this.height = height;
@@ -81,110 +84,119 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
81
84
  return Print6ColCanvasDimensions;
82
85
  }());
83
86
 
84
- var COLUMN_WIDTH_MM$1 = 30.8772;
85
- var GUTTER_WIDTH_MM$1 = 2.1053;
86
- var PIXELS_PER_MM$2 = 3.937;
87
+ var COLUMN_WIDTH_MM = 30.8772;
88
+ var GUTTER_WIDTH_MM = 2.1053;
89
+ var PIXELS_PER_MM = 3.937;
87
90
  var Print8ColCanvasDimensions = /** @class */ (function () {
88
91
  function Print8ColCanvasDimensions(width, height) {
89
92
  this.widthUnit = "column(s)";
90
93
  this.heightUnit = "cm";
91
94
  this.width = width;
92
95
  this.gutterCount = Math.max(0, width - 1);
93
- this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
94
- this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
96
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
97
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM;
95
98
  this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
96
- this.widthPx = _.round(this.widthMm * PIXELS_PER_MM$2);
99
+ this.widthPx = _.round(this.widthMm * PIXELS_PER_MM);
97
100
  this.height = height;
98
101
  this.heightMm = Math.max(0, height * 10);
99
- this.heightPx = _.round(this.heightMm * PIXELS_PER_MM$2);
102
+ this.heightPx = _.round(this.heightMm * PIXELS_PER_MM);
100
103
  }
101
104
  Print8ColCanvasDimensions.prototype.withSize = function (width, height) {
102
105
  return new Print8ColCanvasDimensions(width, height);
103
106
  };
104
107
  Print8ColCanvasDimensions.prototype.widthPxToMm = function (px) {
105
- return px / PIXELS_PER_MM$2;
108
+ return px / PIXELS_PER_MM;
106
109
  };
107
110
  Print8ColCanvasDimensions.prototype.heightPxToMm = function (px) {
108
- return px / PIXELS_PER_MM$2;
111
+ return px / PIXELS_PER_MM;
109
112
  };
110
113
  return Print8ColCanvasDimensions;
111
114
  }());
112
115
 
113
- /*! *****************************************************************************
114
- Copyright (c) Microsoft Corporation.
115
-
116
- Permission to use, copy, modify, and/or distribute this software for any
117
- purpose with or without fee is hereby granted.
118
-
119
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
120
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
121
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
122
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
123
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
124
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
125
- PERFORMANCE OF THIS SOFTWARE.
126
- ***************************************************************************** */
127
- /* global Reflect, Promise */
128
-
129
- var extendStatics = function(d, b) {
130
- extendStatics = Object.setPrototypeOf ||
131
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
132
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
133
- return extendStatics(d, b);
116
+ /******************************************************************************
117
+ Copyright (c) Microsoft Corporation.
118
+
119
+ Permission to use, copy, modify, and/or distribute this software for any
120
+ purpose with or without fee is hereby granted.
121
+
122
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
123
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
124
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
125
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
126
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
127
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
128
+ PERFORMANCE OF THIS SOFTWARE.
129
+ ***************************************************************************** */
130
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
131
+
132
+ var extendStatics = function(d, b) {
133
+ extendStatics = Object.setPrototypeOf ||
134
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
135
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
136
+ return extendStatics(d, b);
137
+ };
138
+
139
+ function __extends(d, b) {
140
+ if (typeof b !== "function" && b !== null)
141
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
142
+ extendStatics(d, b);
143
+ function __() { this.constructor = d; }
144
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
145
+ }
146
+
147
+ function __awaiter(thisArg, _arguments, P, generator) {
148
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
149
+ return new (P || (P = Promise))(function (resolve, reject) {
150
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
151
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
152
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
153
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
154
+ });
155
+ }
156
+
157
+ function __generator(thisArg, body) {
158
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
159
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
160
+ function verb(n) { return function (v) { return step([n, v]); }; }
161
+ function step(op) {
162
+ if (f) throw new TypeError("Generator is already executing.");
163
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
164
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
165
+ if (y = 0, t) op = [op[0] & 2, t.value];
166
+ switch (op[0]) {
167
+ case 0: case 1: t = op; break;
168
+ case 4: _.label++; return { value: op[1], done: false };
169
+ case 5: _.label++; y = op[1]; op = [0]; continue;
170
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
171
+ default:
172
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
173
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
174
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
175
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
176
+ if (t[2]) _.ops.pop();
177
+ _.trys.pop(); continue;
178
+ }
179
+ op = body.call(thisArg, _);
180
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
181
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
182
+ }
183
+ }
184
+
185
+ function __spreadArray(to, from, pack) {
186
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
187
+ if (ar || !(i in from)) {
188
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
189
+ ar[i] = from[i];
190
+ }
191
+ }
192
+ return to.concat(ar || Array.prototype.slice.call(from));
193
+ }
194
+
195
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
196
+ var e = new Error(message);
197
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
134
198
  };
135
199
 
136
- function __extends(d, b) {
137
- extendStatics(d, b);
138
- function __() { this.constructor = d; }
139
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
140
- }
141
-
142
- function __awaiter(thisArg, _arguments, P, generator) {
143
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
144
- return new (P || (P = Promise))(function (resolve, reject) {
145
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
146
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
147
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
148
- step((generator = generator.apply(thisArg, _arguments || [])).next());
149
- });
150
- }
151
-
152
- function __generator(thisArg, body) {
153
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
154
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
155
- function verb(n) { return function (v) { return step([n, v]); }; }
156
- function step(op) {
157
- if (f) throw new TypeError("Generator is already executing.");
158
- while (_) try {
159
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
160
- if (y = 0, t) op = [op[0] & 2, t.value];
161
- switch (op[0]) {
162
- case 0: case 1: t = op; break;
163
- case 4: _.label++; return { value: op[1], done: false };
164
- case 5: _.label++; y = op[1]; op = [0]; continue;
165
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
166
- default:
167
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
168
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
169
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
170
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
171
- if (t[2]) _.ops.pop();
172
- _.trys.pop(); continue;
173
- }
174
- op = body.call(thisArg, _);
175
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
176
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
177
- }
178
- }
179
-
180
- function __spreadArrays() {
181
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
182
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
183
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
184
- r[k] = a[j];
185
- return r;
186
- }
187
-
188
200
  var Font = /** @class */ (function () {
189
201
  function Font() {
190
202
  }
@@ -287,12 +299,110 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
287
299
  return RedrawAllLayoutFunction;
288
300
  }());
289
301
 
302
+ var RepositionCutoffsLayoutFunction = /** @class */ (function () {
303
+ function RepositionCutoffsLayoutFunction() {
304
+ }
305
+ RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
306
+ canvas.getObjectsByTypeInternal(exports.ObjectType.CUTOFF)
307
+ .forEach(function (cutoff) { return cutoff.updatePosition(); });
308
+ };
309
+ return RepositionCutoffsLayoutFunction;
310
+ }());
311
+
312
+ var RepositionBordersLayoutFunction = /** @class */ (function () {
313
+ function RepositionBordersLayoutFunction() {
314
+ }
315
+ RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
316
+ canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
317
+ .forEach(function (border) { return border.updatePosition(); });
318
+ };
319
+ return RepositionBordersLayoutFunction;
320
+ }());
321
+
322
+ var PinToBottomLayoutFunction = /** @class */ (function () {
323
+ function PinToBottomLayoutFunction() {
324
+ }
325
+ PinToBottomLayoutFunction.prototype.execute = function (canvas) {
326
+ canvas.getObjectsInternal()
327
+ .forEach(function (object) { return object.moveToPinnedPosition(); });
328
+ };
329
+ return PinToBottomLayoutFunction;
330
+ }());
331
+
332
+ var ResizeCanvasLayoutFunction = /** @class */ (function () {
333
+ function ResizeCanvasLayoutFunction() {
334
+ }
335
+ ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
336
+ var _a, _b;
337
+ if (canvas.getLayoutManager().isEnforcedPositioning)
338
+ return;
339
+ if ((_b = (_a = canvas === null || canvas === void 0 ? void 0 : canvas.getDimensionsRestrictions()) === null || _a === void 0 ? void 0 : _a.fixed) !== null && _b !== void 0 ? _b : false)
340
+ return;
341
+ var currentDimensions = canvas.getDimensions();
342
+ var baseDimensions = canvas.getBaseDimensions();
343
+ var textHeightIncreasePx = ___default["default"](canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
344
+ .filter(function (text) { return text.isResizeCanvas(); })
345
+ .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
346
+ var increase = baseDimensions.withSize(currentDimensions.width, 0);
347
+ while (increase.heightPx < textHeightIncreasePx) {
348
+ increase = increase.withSize(increase.width, increase.height + 1);
349
+ }
350
+ var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
351
+ if (currentDimensions.height !== targetHeight.height) {
352
+ canvas.setDimensions(targetHeight);
353
+ }
354
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
355
+ canvas.redraw();
356
+ };
357
+ return ResizeCanvasLayoutFunction;
358
+ }());
359
+
360
+ exports.LayoutManager = void 0;
290
361
  (function (LayoutManager) {
291
362
  LayoutManager["LEGACY"] = "LEGACY";
292
363
  LayoutManager["STANDARD"] = "STANDARD";
293
364
  LayoutManager["ADVANCED"] = "ADVANCED";
294
365
  })(exports.LayoutManager || (exports.LayoutManager = {}));
295
366
 
367
+ var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
368
+ function RepositionBackgroundsLayoutFunction() {
369
+ }
370
+ RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
371
+ canvas.getObjectsByTypeInternal(exports.ObjectType.BACKGROUND_IMAGE)
372
+ .forEach(function (border) { return border.updatePosition(); });
373
+ };
374
+ return RepositionBackgroundsLayoutFunction;
375
+ }());
376
+
377
+ var AdvancedLayoutManager = /** @class */ (function (_super) {
378
+ __extends(AdvancedLayoutManager, _super);
379
+ function AdvancedLayoutManager(canvas) {
380
+ var _this = _super.call(this, canvas) || this;
381
+ _this.key = exports.LayoutManager.ADVANCED;
382
+ _this.pinToBottom = new PinToBottomLayoutFunction();
383
+ _this.redrawAll = new RedrawAllLayoutFunction();
384
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
385
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
386
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
387
+ _this.resizeCanvas = new ResizeCanvasLayoutFunction();
388
+ return _this;
389
+ }
390
+ AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
391
+ this.pinToBottom.execute(this.canvas);
392
+ this.repositionCutoffs.execute(this.canvas);
393
+ this.repositionBorders.execute(this.canvas);
394
+ this.repositionBackgrounds.execute(this.canvas);
395
+ this.redrawAll.execute(this.canvas);
396
+ };
397
+ AdvancedLayoutManager.prototype.onTextChange = function () {
398
+ this.resizeCanvas.execute(this.canvas);
399
+ };
400
+ AdvancedLayoutManager.prototype.onObjectListChange = function () {
401
+ this.redrawAll.execute(this.canvas);
402
+ };
403
+ return AdvancedLayoutManager;
404
+ }(AbstractLayoutManager));
405
+
296
406
  var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
297
407
  function UpdateObjectDimensionsLayoutFunction() {
298
408
  }
@@ -310,7 +420,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
310
420
  var canvasMargin = canvas.getMargin();
311
421
  var canvasDimensions = canvas.getDimensions();
312
422
  var allObjects = canvas.getObjectsByTypesInternal(exports.ObjectType.TEXT, exports.ObjectType.RICH_TEXT, exports.ObjectType.IMAGE, exports.ObjectType.RECTANGLE, exports.ObjectType.VERTICAL_RULE, exports.ObjectType.HORIZONTAL_RULE);
313
- var objects = _(allObjects)
423
+ var objects = ___default["default"](allObjects)
314
424
  .partition(function (object) { return object.isPinToBottom(); })
315
425
  .value();
316
426
  var footerObjects = objects[0];
@@ -334,13 +444,14 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
334
444
  var currentColumnWidthPercent = 0;
335
445
  _.each(footerRows.rows, function (row) {
336
446
  _.each(row.objects, function (object) {
447
+ var _a, _b, _c;
337
448
  var columnOffset = currentColumnWidthPercent / 100 * layoutAreaWidth;
338
- var objectMargin = tsOptchain.oc(object.getMargin()).left(0);
449
+ var objectMargin = (_b = (_a = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _a === void 0 ? void 0 : _a.left) !== null && _b !== void 0 ? _b : 0;
339
450
  var left = canvasMargin.left + columnOffset + objectMargin;
340
451
  if (object.getType() === exports.ObjectType.VERTICAL_RULE)
341
452
  object.setPosition({ height: row.height });
342
453
  object.setPosition({
343
- top: nextObjectTop + tsOptchain.oc(object.getMargin()).top(0),
454
+ top: nextObjectTop + ((_c = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _c === void 0 ? void 0 : _c.top) || 0,
344
455
  left: left
345
456
  });
346
457
  currentColumnWidthPercent += object.getColumnWidthPercent();
@@ -350,6 +461,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
350
461
  });
351
462
  };
352
463
  StackObjectsLayoutFunction.prototype.layoutBody = function (bodyRows, canvas, footerHeight) {
464
+ var _a, _b, _c, _d;
353
465
  var canvasDimensions = canvas.getDimensions();
354
466
  var canvasMargin = canvas.getMargin();
355
467
  var workableWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
@@ -362,10 +474,10 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
362
474
  for (var i = 0; i < bodyRows.rows.length; i++) {
363
475
  var row = bodyRows.rows[i];
364
476
  var nextRow = bodyRows.rows[i + 1];
365
- for (var _i = 0, _a = row.objects; _i < _a.length; _i++) {
366
- var object = _a[_i];
477
+ for (var _i = 0, _e = row.objects; _i < _e.length; _i++) {
478
+ var object = _e[_i];
367
479
  var columnOffset = currentColumnWidthPercent / 100 * workableWidth;
368
- var objectMargin = tsOptchain.oc(object.getMargin()).left(0);
480
+ var objectMargin = (_a = object.getMargin().left) !== null && _a !== void 0 ? _a : 0;
369
481
  var objectLeft = canvasMargin.left + columnOffset + objectMargin;
370
482
  if (object.getType() === exports.ObjectType.TEXT && object.isBulleted())
371
483
  objectLeft += object.getBulletMargin();
@@ -374,7 +486,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
374
486
  if (object.getType() === exports.ObjectType.VERTICAL_RULE)
375
487
  return;
376
488
  object.setPosition({
377
- top: nextObjectTop + tsOptchain.oc(object.getMargin()).top(0),
489
+ top: nextObjectTop + ((_b = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _b === void 0 ? void 0 : _b.top) || 0,
378
490
  left: objectLeft
379
491
  });
380
492
  currentColumnWidthPercent += object.getColumnWidthPercent();
@@ -382,16 +494,17 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
382
494
  currentColumnWidthPercent = 0;
383
495
  nextObjectTop += row.height;
384
496
  var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
385
- var nextRowIsHR = tsOptchain.oc(nextRow).objects.length() === 1 && tsOptchain.oc(nextRow).objects()[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
497
+ var nextRowIsHR = ((_c = nextRow === null || nextRow === void 0 ? void 0 : nextRow.objects) === null || _c === void 0 ? void 0 : _c.length) === 1 && ((_d = nextRow === null || nextRow === void 0 ? void 0 : nextRow.objects[0]) === null || _d === void 0 ? void 0 : _d.getType()) === exports.ObjectType.HORIZONTAL_RULE;
386
498
  if (!thisRowIsHR && !nextRowIsHR) {
387
499
  nextObjectTop += spaceSize;
388
500
  }
389
501
  }
390
502
  };
391
503
  StackObjectsLayoutFunction.prototype.applyWidths = function (objects, layoutWidth) {
392
- _(objects).forEach(function (object) {
504
+ ___default["default"](objects).forEach(function (object) {
505
+ var _a, _b;
393
506
  var targetWidth = object.getColumnWidthPercent() / 100 * layoutWidth;
394
- var actualWidth = targetWidth - tsOptchain.oc(object.getMargin()).left(0) - tsOptchain.oc(object.getMargin()).right(0);
507
+ var actualWidth = targetWidth - (((_a = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _a === void 0 ? void 0 : _a.left) || 0) - (((_b = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _b === void 0 ? void 0 : _b.right) || 0);
395
508
  if (object.getType() === exports.ObjectType.VERTICAL_RULE)
396
509
  return;
397
510
  if (object.getType() === exports.ObjectType.TEXT && object.isBulleted())
@@ -405,10 +518,11 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
405
518
  });
406
519
  };
407
520
  StackObjectsLayoutFunction.prototype.adjustCanvasSize = function (canvas, requiredHeight) {
408
- if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
521
+ var _a, _b, _c, _d;
522
+ if ((_a = canvas === null || canvas === void 0 ? void 0 : canvas.getDimensionsRestrictions()) === null || _a === void 0 ? void 0 : _a.fixed)
409
523
  return;
410
524
  var dimensions = canvas.getDimensions();
411
- var minHeight = tsOptchain.oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
525
+ var minHeight = (_d = (_c = (_b = canvas === null || canvas === void 0 ? void 0 : canvas.getDimensionsRestrictions()) === null || _b === void 0 ? void 0 : _b.height) === null || _c === void 0 ? void 0 : _c.min) !== null && _d !== void 0 ? _d : MIN_MAGNITUDE;
412
526
  var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
413
527
  while (targetDimensions.heightPx < requiredHeight) {
414
528
  targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
@@ -441,17 +555,19 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
441
555
  return result;
442
556
  };
443
557
  StackObjectsLayoutFunction.prototype.getObjectHeight = function (element) {
558
+ var _a, _b;
444
559
  return element.getBoundingBox().height
445
- + tsOptchain.oc(element.getMargin()).top(0)
446
- + tsOptchain.oc(element.getMargin()).bottom(0);
560
+ + (((_a = element === null || element === void 0 ? void 0 : element.getMargin()) === null || _a === void 0 ? void 0 : _a.top) || 0)
561
+ + (((_b = element === null || element === void 0 ? void 0 : element.getMargin()) === null || _b === void 0 ? void 0 : _b.bottom) || 0);
447
562
  };
448
563
  StackObjectsLayoutFunction.prototype.countSpaces = function (rows) {
564
+ var _a, _b;
449
565
  var count = 0;
450
566
  for (var i = 0; i < rows.rows.length - 1; i++) {
451
567
  var row = rows.rows[i];
452
568
  var nextRow = rows.rows[i + 1];
453
569
  var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
454
- var nextRowIsHR = tsOptchain.oc(nextRow).objects.length() === 1 && tsOptchain.oc(nextRow).objects()[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
570
+ var nextRowIsHR = ((_a = nextRow === null || nextRow === void 0 ? void 0 : nextRow.objects) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = nextRow === null || nextRow === void 0 ? void 0 : nextRow.objects[0]) === null || _b === void 0 ? void 0 : _b.getType()) === exports.ObjectType.HORIZONTAL_RULE;
455
571
  if (!thisRowIsHR && !nextRowIsHR) {
456
572
  count++;
457
573
  }
@@ -461,26 +577,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
461
577
  return StackObjectsLayoutFunction;
462
578
  }());
463
579
 
464
- var RepositionBordersLayoutFunction = /** @class */ (function () {
465
- function RepositionBordersLayoutFunction() {
466
- }
467
- RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
468
- canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
469
- .forEach(function (border) { return border.updatePosition(); });
470
- };
471
- return RepositionBordersLayoutFunction;
472
- }());
473
-
474
- var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
475
- function RepositionBackgroundsLayoutFunction() {
476
- }
477
- RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
478
- canvas.getObjectsByTypeInternal(exports.ObjectType.BACKGROUND_IMAGE)
479
- .forEach(function (border) { return border.updatePosition(); });
480
- };
481
- return RepositionBackgroundsLayoutFunction;
482
- }());
483
-
484
580
  var StandardLayoutManager = /** @class */ (function (_super) {
485
581
  __extends(StandardLayoutManager, _super);
486
582
  function StandardLayoutManager(canvas) {
@@ -713,14 +809,15 @@ var AbstractCanvasObject = /** @class */ (function () {
713
809
  * @inheritDoc
714
810
  */
715
811
  AbstractCanvasObject.prototype.setMargin = function (margin) {
812
+ var _a, _b;
716
813
  if (!margin)
717
814
  return;
718
- var newMargin = tsOptchain.oc(this.data).margin({
815
+ var newMargin = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.margin) !== null && _b !== void 0 ? _b : {
719
816
  top: 0,
720
817
  right: 0,
721
818
  bottom: 0,
722
819
  left: 0
723
- });
820
+ };
724
821
  if (margin.top != undefined)
725
822
  newMargin.top = margin.top || 0;
726
823
  if (margin.right != undefined)
@@ -737,7 +834,8 @@ var AbstractCanvasObject = /** @class */ (function () {
737
834
  * @inheritDoc
738
835
  */
739
836
  AbstractCanvasObject.prototype.getColumnWidthPercent = function () {
740
- return Math.max(Math.min(tsOptchain.oc(this.data).columnWidthPercent(100), 100), 0);
837
+ var _a, _b;
838
+ return Math.max(Math.min((_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.columnWidthPercent) !== null && _b !== void 0 ? _b : 100, 100), 0);
741
839
  };
742
840
  /**
743
841
  * @override
@@ -1819,6 +1917,20 @@ var RichText = /** @class */ (function (_super) {
1819
1917
  return RichText;
1820
1918
  }(Image));
1821
1919
 
1920
+ exports.ObjectType = void 0;
1921
+ (function (ObjectType) {
1922
+ ObjectType["TEXT"] = "TEXT";
1923
+ ObjectType["BORDER"] = "BORDER";
1924
+ ObjectType["IMAGE"] = "IMAGE";
1925
+ ObjectType["RECTANGLE"] = "RECTANGLE";
1926
+ ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
1927
+ ObjectType["CUTOFF"] = "CUTOFF";
1928
+ ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
1929
+ ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
1930
+ ObjectType["RICH_TEXT"] = "RICH_TEXT";
1931
+ ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
1932
+ })(exports.ObjectType || (exports.ObjectType = {}));
1933
+
1822
1934
  var Text = /** @class */ (function (_super) {
1823
1935
  __extends(Text, _super);
1824
1936
  function Text(canvas, fabricObject, persistedField) {
@@ -1872,6 +1984,21 @@ var Text = /** @class */ (function (_super) {
1872
1984
  this.data.userText = this.fabricObject.text;
1873
1985
  this.text$.next(this.fabricObject.text);
1874
1986
  };
1987
+ Text.prototype.replaceTextWithStyle = function (target, replacement) {
1988
+ var start = this.getText().indexOf(target);
1989
+ var styles = this.getReplacementStyle(target, replacement);
1990
+ this.fabricObject.insertChars(replacement, styles, start, start + target.length);
1991
+ this.redraw();
1992
+ this.data.userText = this.fabricObject.text;
1993
+ this.text$.next(this.fabricObject.text);
1994
+ };
1995
+ Text.prototype.getReplacementStyle = function (target, replacement) {
1996
+ var start = this.getText().indexOf(target);
1997
+ var lineIndex = (this.getText().substring(0, start).split(Text.NEW_LINE).length - 1);
1998
+ var lines = this.getText().split(Text.NEW_LINE);
1999
+ var startWithinLine = lines[lineIndex].indexOf(target);
2000
+ return Array(replacement.length).fill(this.fabricObject.styles[lineIndex][startWithinLine]);
2001
+ };
1875
2002
  /**
1876
2003
  * @override
1877
2004
  * @inheritDoc
@@ -1986,7 +2113,7 @@ var Text = /** @class */ (function (_super) {
1986
2113
  Text.prototype.setBoldRegion = function (start, end, bold) {
1987
2114
  if (bold === void 0) { bold = true; }
1988
2115
  if (start > end)
1989
- throw Error("Bad region specified: [" + start + " - " + end + "]");
2116
+ throw Error("Bad region specified: [".concat(start, " - ").concat(end, "]"));
1990
2117
  for (var i = start; i < end; i++) {
1991
2118
  var style = this.fabricObject.getStyleAtPosition(i, true);
1992
2119
  var font = this.fontLibrary.getFont(style.fontFamily);
@@ -2017,7 +2144,7 @@ var Text = /** @class */ (function (_super) {
2017
2144
  Text.prototype.setItalicRegion = function (start, end, italic) {
2018
2145
  if (italic === void 0) { italic = true; }
2019
2146
  if (start > end)
2020
- throw Error("Bad region specified: [" + start + " - " + end + "]");
2147
+ throw Error("Bad region specified: [".concat(start, " - ").concat(end, "]"));
2021
2148
  this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" }, start, end);
2022
2149
  this.redraw();
2023
2150
  };
@@ -2168,7 +2295,7 @@ var Text = /** @class */ (function (_super) {
2168
2295
  if (!this.isBulleted())
2169
2296
  return 0;
2170
2297
  var fontSize = 0;
2171
- _.each(this.fabricObject._textLines, function (textLine, lineIndex) {
2298
+ ___default["default"].each(this.fabricObject._textLines, function (textLine, lineIndex) {
2172
2299
  fontSize = Math.max(fontSize, _this_1.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
2173
2300
  });
2174
2301
  return fontSize * 0.6;
@@ -2181,7 +2308,7 @@ var Text = /** @class */ (function (_super) {
2181
2308
  if (!this.isOrderedList())
2182
2309
  return 0;
2183
2310
  var orderedListMarkerEntities = this.fabricObject._orderedListMarkerEntities;
2184
- var max = _(orderedListMarkerEntities)
2311
+ var max = ___default["default"](orderedListMarkerEntities)
2185
2312
  .filter(function (x) { return !!x; })
2186
2313
  .map(function (x) { return x.getBoundingRect(true, true).width; })
2187
2314
  .max();
@@ -2247,9 +2374,10 @@ var Text = /** @class */ (function (_super) {
2247
2374
  * @inheritDoc
2248
2375
  */
2249
2376
  Text.prototype.enableBullets = function () {
2377
+ var _a;
2250
2378
  this.disableOrderedList();
2251
2379
  this.fabricObject["objectCaching"] = false;
2252
- this.fabricObject["_bullets"] = this.fabricObject["_bullets"] || {};
2380
+ this.fabricObject["_bullets"] = (_a = this.fabricObject["_bullets"]) !== null && _a !== void 0 ? _a : {};
2253
2381
  this.data.bulleted = true;
2254
2382
  this.notifyCanvasOfTextChanges();
2255
2383
  this.redraw();
@@ -2316,7 +2444,7 @@ var Text = /** @class */ (function (_super) {
2316
2444
  if (this.data.bulleted) {
2317
2445
  var bullets = this.fabricObject["_bullets"];
2318
2446
  delete this.fabricObject["_bullets"];
2319
- _.each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2447
+ ___default["default"].each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2320
2448
  this.fabricObject["objectCaching"] = true;
2321
2449
  }
2322
2450
  };
@@ -2325,7 +2453,7 @@ var Text = /** @class */ (function (_super) {
2325
2453
  if (this.fabricObject._isOrderedList) {
2326
2454
  var markerEntities = this.fabricObject._orderedListMarkerEntities;
2327
2455
  delete this.fabricObject._orderedListMarkerEntities;
2328
- _.each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2456
+ ___default["default"].each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2329
2457
  this.fabricObject["objectCaching"] = true;
2330
2458
  }
2331
2459
  };
@@ -2338,12 +2466,13 @@ var Text = /** @class */ (function (_super) {
2338
2466
  var originalRender = this.fabricObject["_render"];
2339
2467
  var fabric = this.canvas.fabric;
2340
2468
  this.fabricObject["_render"] = function (ctx) {
2469
+ var _a;
2341
2470
  var fabricText = this;
2342
2471
  if (fabricText["_bullets"]) {
2343
2472
  // Determine list of active bullets
2344
2473
  var currentBullets_1 = fabricText["_bullets"];
2345
2474
  var activeBullets_1 = {};
2346
- _.each(fabricText._textLines, function (textLine, lineIndex) {
2475
+ ___default["default"].each(fabricText._textLines, function (textLine, lineIndex) {
2347
2476
  if (textLine.length) {
2348
2477
  // Start of real lines will have offset 0 in styleMap
2349
2478
  var styleMap = fabricText._styleMap[lineIndex];
@@ -2377,13 +2506,13 @@ var Text = /** @class */ (function (_super) {
2377
2506
  var canvas_1 = fabricText.canvas;
2378
2507
  var canvasDirty_1 = false;
2379
2508
  canvas_1.renderOnAddRemove = false;
2380
- _.each(activeBullets_1, function (bullet) {
2509
+ ___default["default"].each(activeBullets_1, function (bullet) {
2381
2510
  if (!canvas_1.contains(bullet)) {
2382
2511
  canvas_1.add(bullet);
2383
2512
  canvasDirty_1 = true;
2384
2513
  }
2385
2514
  });
2386
- _.each(currentBullets_1, function (bullet, key) {
2515
+ ___default["default"].each(currentBullets_1, function (bullet, key) {
2387
2516
  if (!activeBullets_1[key]) {
2388
2517
  canvas_1.remove(bullet);
2389
2518
  canvasDirty_1 = true;
@@ -2397,9 +2526,9 @@ var Text = /** @class */ (function (_super) {
2397
2526
  }
2398
2527
  }
2399
2528
  if (fabricText._isOrderedList) {
2400
- var existingMarkers_1 = fabricText._orderedListMarkerEntities || [];
2529
+ var existingMarkers_1 = (_a = fabricText._orderedListMarkerEntities) !== null && _a !== void 0 ? _a : [];
2401
2530
  var activeMarkers_1 = [];
2402
- _.each(fabricText._textLines, function (textLine, lineIndex) {
2531
+ ___default["default"].each(fabricText._textLines, function (textLine, lineIndex) {
2403
2532
  if (textLine.length) {
2404
2533
  // Start of real lines will have offset 0 in styleMap
2405
2534
  var styleMap = fabricText._styleMap[lineIndex];
@@ -2410,7 +2539,7 @@ var Text = /** @class */ (function (_super) {
2410
2539
  }
2411
2540
  else {
2412
2541
  // Create new marker for this line
2413
- var textbox = new fabric.Textbox(lineIndex + ".", {
2542
+ var textbox = new fabric.Textbox("".concat(lineIndex, "."), {
2414
2543
  left: 0,
2415
2544
  top: 0,
2416
2545
  fill: fabricText.fill,
@@ -2432,7 +2561,7 @@ var Text = /** @class */ (function (_super) {
2432
2561
  var canvas_2 = fabricText.canvas;
2433
2562
  var canvasDirty_2 = false;
2434
2563
  canvas_2.renderOnAddRemove = false;
2435
- _.each(activeMarkers_1, function (marker) {
2564
+ ___default["default"].each(activeMarkers_1, function (marker) {
2436
2565
  if (!marker)
2437
2566
  return;
2438
2567
  if (!canvas_2.contains(marker)) {
@@ -2440,7 +2569,7 @@ var Text = /** @class */ (function (_super) {
2440
2569
  canvasDirty_2 = true;
2441
2570
  }
2442
2571
  });
2443
- _.each(existingMarkers_1, function (marker, key) {
2572
+ ___default["default"].each(existingMarkers_1, function (marker, key) {
2444
2573
  if (!marker)
2445
2574
  return;
2446
2575
  if (!activeMarkers_1[key]) {
@@ -2509,7 +2638,7 @@ var Text = /** @class */ (function (_super) {
2509
2638
  left: fabricText.left + xOffset,
2510
2639
  top: fabricText.top + yOffset,
2511
2640
  angle: fabricText.angle,
2512
- text: lineNumber + "."
2641
+ text: "".concat(lineNumber, ".")
2513
2642
  });
2514
2643
  }
2515
2644
  originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
@@ -2566,6 +2695,7 @@ var Text = /** @class */ (function (_super) {
2566
2695
  Text.prototype.notifyCanvasOfTextChanges = function () {
2567
2696
  this.canvas.notifyTextChanged();
2568
2697
  };
2698
+ Text.NEW_LINE = "\n";
2569
2699
  return Text;
2570
2700
  }(AbstractCanvasObject));
2571
2701
  var TextSelection = /** @class */ (function () {
@@ -2720,6 +2850,7 @@ var DefaultCanvasProfile = /** @class */ (function () {
2720
2850
  return DefaultCanvasProfile;
2721
2851
  }());
2722
2852
 
2853
+ exports.ImageType = void 0;
2723
2854
  (function (ImageType) {
2724
2855
  ImageType["DEFAULT"] = "DEFAULT";
2725
2856
  ImageType["BACKGROUND"] = "BACKGROUND";
@@ -2727,19 +2858,6 @@ var DefaultCanvasProfile = /** @class */ (function () {
2727
2858
  ImageType["PHOTO"] = "PHOTO";
2728
2859
  })(exports.ImageType || (exports.ImageType = {}));
2729
2860
 
2730
- (function (ObjectType) {
2731
- ObjectType["TEXT"] = "TEXT";
2732
- ObjectType["BORDER"] = "BORDER";
2733
- ObjectType["IMAGE"] = "IMAGE";
2734
- ObjectType["RECTANGLE"] = "RECTANGLE";
2735
- ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
2736
- ObjectType["CUTOFF"] = "CUTOFF";
2737
- ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
2738
- ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
2739
- ObjectType["RICH_TEXT"] = "RICH_TEXT";
2740
- ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
2741
- })(exports.ObjectType || (exports.ObjectType = {}));
2742
-
2743
2861
  var AbstractInteractiveCanvas = /** @class */ (function () {
2744
2862
  function AbstractInteractiveCanvas(fabric, fabricCanvas, devicePixelRatio) {
2745
2863
  this.fabric = fabric;
@@ -2921,11 +3039,12 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2921
3039
  * @inheritDoc
2922
3040
  */
2923
3041
  AbstractInteractiveCanvas.prototype.setDimensionRestrictions = function (restrictions) {
3042
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2924
3043
  this.dimensionRestrictions$.next(restrictions);
2925
3044
  var dimensions = this.getDimensions();
2926
3045
  if (this.dimensionsExceedRestrictions(dimensions)) {
2927
3046
  var newDimensions = dimensions
2928
- .withSize(Math.min(Math.max(tsOptchain.oc(restrictions).width.min(dimensions.width), dimensions.width), Math.max(tsOptchain.oc(restrictions).width.max(dimensions.width))), Math.min(Math.max(tsOptchain.oc(restrictions).height.min(dimensions.height), dimensions.height), Math.max(tsOptchain.oc(restrictions).height.max(dimensions.height))));
3047
+ .withSize(Math.min(Math.max((_b = (_a = restrictions === null || restrictions === void 0 ? void 0 : restrictions.width) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : dimensions.width, dimensions.width), Math.max((_d = (_c = restrictions === null || restrictions === void 0 ? void 0 : restrictions.width) === null || _c === void 0 ? void 0 : _c.max) !== null && _d !== void 0 ? _d : dimensions.width)), Math.min(Math.max((_f = (_e = restrictions === null || restrictions === void 0 ? void 0 : restrictions.height) === null || _e === void 0 ? void 0 : _e.min) !== null && _f !== void 0 ? _f : dimensions.height, dimensions.height), Math.max((_h = (_g = restrictions === null || restrictions === void 0 ? void 0 : restrictions.height) === null || _g === void 0 ? void 0 : _g.max) !== null && _h !== void 0 ? _h : dimensions.height)));
2929
3048
  this.setBaseDimensions(newDimensions);
2930
3049
  }
2931
3050
  };
@@ -2994,7 +3113,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2994
3113
  * @inheritDoc
2995
3114
  */
2996
3115
  AbstractInteractiveCanvas.prototype.getObjectsByTypeInternal = function (type) {
2997
- return _(this.getObjectsInternal())
3116
+ return ___default["default"](this.getObjectsInternal())
2998
3117
  .filter(function (object) { return object.getType() === type; })
2999
3118
  .value();
3000
3119
  };
@@ -3007,8 +3126,8 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3007
3126
  for (var _i = 0; _i < arguments.length; _i++) {
3008
3127
  types[_i] = arguments[_i];
3009
3128
  }
3010
- return _(this.getObjectsInternal())
3011
- .filter(function (object) { return _(types).includes(object.getType()); })
3129
+ return ___default["default"](this.getObjectsInternal())
3130
+ .filter(function (object) { return ___default["default"](types).includes(object.getType()); })
3012
3131
  .value();
3013
3132
  };
3014
3133
  /**
@@ -3025,7 +3144,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3025
3144
  AbstractInteractiveCanvas.prototype.removeObject = function (target) {
3026
3145
  var concreteObject = this.findFabricObject(target.getId());
3027
3146
  this.fabricCanvas.remove(concreteObject);
3028
- this.objects$.next(_(this.objects$.value)
3147
+ this.objects$.next(___default["default"](this.objects$.value)
3029
3148
  .filter(function (object) { return object.getId() !== target.getId(); })
3030
3149
  .value());
3031
3150
  this.onObjectListChange();
@@ -3325,7 +3444,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3325
3444
  * @inheritDoc
3326
3445
  */
3327
3446
  AbstractInteractiveCanvas.prototype.setPrefillData = function (data) {
3328
- _(this.getObjectsByTypeInternal(exports.ObjectType.TEXT)).each(function (object) {
3447
+ ___default["default"](this.getObjectsByTypeInternal(exports.ObjectType.TEXT)).each(function (object) {
3329
3448
  var prefillType = object.getPrefillType();
3330
3449
  if (prefillType !== undefined) {
3331
3450
  object.setText(data[prefillType] || "");
@@ -3339,10 +3458,10 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3339
3458
  AbstractInteractiveCanvas.prototype.distributeObjectsVertically = function () {
3340
3459
  var margin = this.getMargin();
3341
3460
  var canvasHeight = this.getDimensions().heightPx;
3342
- var objectsToLayout = _(this.getObjectsByTypesInternal(exports.ObjectType.TEXT, exports.ObjectType.IMAGE))
3461
+ var objectsToLayout = ___default["default"](this.getObjectsByTypesInternal(exports.ObjectType.TEXT, exports.ObjectType.IMAGE))
3343
3462
  .sortBy(function (x) { return x.getBoundingBox().top; })
3344
3463
  .value();
3345
- var objectsHeight = _.reduce(objectsToLayout, function (total, element) { return total + element.getBoundingBox().height; }, 0);
3464
+ var objectsHeight = ___default["default"].reduce(objectsToLayout, function (total, element) { return total + element.getBoundingBox().height; }, 0);
3346
3465
  var workableHeight = canvasHeight - margin.top - margin.bottom;
3347
3466
  var requiredPadding = workableHeight - objectsHeight;
3348
3467
  var spaceBetween = requiredPadding / (objectsToLayout.length - 1);
@@ -3411,7 +3530,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3411
3530
  * @inheritDoc
3412
3531
  */
3413
3532
  AbstractInteractiveCanvas.prototype.save = function () {
3414
- var objects = _(this.objects$.value)
3533
+ var objects = ___default["default"](this.objects$.value)
3415
3534
  .map(function (x) { return x.persist(); })
3416
3535
  .value();
3417
3536
  var includedProperties = ["id", "_isSlaveObject", "_isOrderedList", "_orderedListStart"];
@@ -3516,7 +3635,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3516
3635
  if (activeObject) {
3517
3636
  this.fabricCanvas.setActiveObject(activeObject);
3518
3637
  }
3519
- return _.replace(base64, /^data:.*;base64,/, "");
3638
+ return ___default["default"].replace(base64, /^data:.*;base64,/, "");
3520
3639
  };
3521
3640
  /**
3522
3641
  * @override
@@ -3554,7 +3673,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3554
3673
  };
3555
3674
  AbstractInteractiveCanvas.prototype.syncObjectList = function () {
3556
3675
  var _this = this;
3557
- var newObjectList = _(this.fabricCanvas.getObjects())
3676
+ var newObjectList = ___default["default"](this.fabricCanvas.getObjects())
3558
3677
  .map(function (obj) { return _this.findObject(obj.id); })
3559
3678
  .filter(function (x) { return x !== undefined; })
3560
3679
  .value();
@@ -3602,7 +3721,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3602
3721
  };
3603
3722
  AbstractInteractiveCanvas.prototype.bindFields = function (persistedFields) {
3604
3723
  var _this = this;
3605
- var bound = _(persistedFields)
3724
+ var bound = ___default["default"](persistedFields)
3606
3725
  .flatMap(function (field) {
3607
3726
  try {
3608
3727
  return [_this.bindField(field)];
@@ -3638,20 +3757,20 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3638
3757
  case exports.ObjectType.BACKGROUND_IMAGE:
3639
3758
  return new BackgroundImage(this, fabricObject, persistedField);
3640
3759
  default:
3641
- throw new Error("Unknown field type: [" + persistedField.type + "]");
3760
+ throw new Error("Unknown field type: [".concat(persistedField.type, "]"));
3642
3761
  }
3643
3762
  };
3644
3763
  AbstractInteractiveCanvas.prototype.findFabricObject = function (id) {
3645
3764
  var objects = this.fabricCanvas.getObjects();
3646
- var fabricObject = _.find(objects, function (o) { return o.id == id; });
3765
+ var fabricObject = ___default["default"].find(objects, function (o) { return o.id == id; });
3647
3766
  if (!fabricObject) {
3648
- throw new Error("Cannot find fabric object with id [" + id + "]");
3767
+ throw new Error("Cannot find fabric object with id [".concat(id, "]"));
3649
3768
  }
3650
3769
  return fabricObject;
3651
3770
  };
3652
3771
  AbstractInteractiveCanvas.prototype.findObject = function (id) {
3653
3772
  //Don't use strict compare here. fabric ids are numbers while ad builder ids are strings... mostly.
3654
- return _.find(this.objects$.value, function (object) { return object.getId() == id; });
3773
+ return ___default["default"].find(this.objects$.value, function (object) { return object.getId() == id; });
3655
3774
  };
3656
3775
  /**
3657
3776
  * Reset zoom and canvas dimensions to 1:1 scale, execute a function, then return the canvas to
@@ -3689,11 +3808,11 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3689
3808
  if (!object) {
3690
3809
  return null;
3691
3810
  }
3692
- return _.find(this.objects$.value, function (field) { return field.getId() == object.id; });
3811
+ return ___default["default"].find(this.objects$.value, function (field) { return field.getId() == object.id; });
3693
3812
  };
3694
3813
  AbstractInteractiveCanvas.prototype.getFieldsByCanvasObject = function (objects) {
3695
3814
  var _this = this;
3696
- return _(objects)
3815
+ return ___default["default"](objects)
3697
3816
  .map(function (obj) { return _this.getFieldByCanvasObject(obj); })
3698
3817
  .reject(function (x) { return !x; })
3699
3818
  .value();
@@ -3701,7 +3820,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3701
3820
  AbstractInteractiveCanvas.prototype.calculateImageCaptureCoefficient = function () {
3702
3821
  var precision = 3;
3703
3822
  var devicePixelRatio = this.devicePixelRatio || 1;
3704
- return _.round(2 / devicePixelRatio, precision);
3823
+ return ___default["default"].round(2 / devicePixelRatio, precision);
3705
3824
  };
3706
3825
  AbstractInteractiveCanvas.prototype.randomId = function () {
3707
3826
  var min = 0;
@@ -3710,22 +3829,23 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3710
3829
  return (new Date()).getTime() + "" + id;
3711
3830
  };
3712
3831
  AbstractInteractiveCanvas.prototype.getLowestTextPoint = function () {
3713
- return _(this.objects$.value)
3832
+ return ___default["default"](this.objects$.value)
3714
3833
  .filter(function (object) { return object.getType() === exports.ObjectType.TEXT; })
3715
3834
  .map(function (text) { return text.getDimensions().top.px + text.getDimensions().height.px; })
3716
3835
  .reduce(function (x, y) { return Math.max(x, y); }, 0);
3717
3836
  };
3718
3837
  AbstractInteractiveCanvas.prototype.trackNewObject = function (object) {
3719
- this.objects$.next(__spreadArrays(this.objects$.value, [object]));
3838
+ this.objects$.next(__spreadArray(__spreadArray([], this.objects$.value, true), [object], false));
3720
3839
  };
3721
3840
  AbstractInteractiveCanvas.prototype.dimensionsExceedRestrictions = function (dimensions) {
3841
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
3722
3842
  var restrictions = this.dimensionRestrictions$.value;
3723
- return tsOptchain.oc(restrictions).height.min() != undefined && dimensions.height < tsOptchain.oc(restrictions).height.min()
3724
- || tsOptchain.oc(restrictions).height.max() != undefined && dimensions.height > tsOptchain.oc(restrictions).height.max()
3725
- || tsOptchain.oc(restrictions).width.min() != undefined && dimensions.width < tsOptchain.oc(restrictions).width.min()
3726
- || tsOptchain.oc(restrictions).width.max() != undefined && dimensions.width > tsOptchain.oc(restrictions).width.max()
3727
- || tsOptchain.oc(restrictions).volume.min() != undefined && dimensions.height * dimensions.width < tsOptchain.oc(restrictions).volume.min()
3728
- || tsOptchain.oc(restrictions).volume.max() != undefined && dimensions.height * dimensions.width > tsOptchain.oc(restrictions).volume.max();
3843
+ return ((_a = restrictions === null || restrictions === void 0 ? void 0 : restrictions.height) === null || _a === void 0 ? void 0 : _a.min) != undefined && dimensions.height < ((_b = restrictions === null || restrictions === void 0 ? void 0 : restrictions.height) === null || _b === void 0 ? void 0 : _b.min)
3844
+ || ((_c = restrictions === null || restrictions === void 0 ? void 0 : restrictions.height) === null || _c === void 0 ? void 0 : _c.max) != undefined && dimensions.height > ((_d = restrictions === null || restrictions === void 0 ? void 0 : restrictions.height) === null || _d === void 0 ? void 0 : _d.max)
3845
+ || ((_e = restrictions === null || restrictions === void 0 ? void 0 : restrictions.width) === null || _e === void 0 ? void 0 : _e.min) != undefined && dimensions.width < ((_f = restrictions === null || restrictions === void 0 ? void 0 : restrictions.width) === null || _f === void 0 ? void 0 : _f.min)
3846
+ || ((_g = restrictions === null || restrictions === void 0 ? void 0 : restrictions.width) === null || _g === void 0 ? void 0 : _g.max) != undefined && dimensions.width > ((_h = restrictions === null || restrictions === void 0 ? void 0 : restrictions.width) === null || _h === void 0 ? void 0 : _h.max)
3847
+ || ((_j = restrictions === null || restrictions === void 0 ? void 0 : restrictions.volume) === null || _j === void 0 ? void 0 : _j.min) != undefined && dimensions.height * dimensions.width < ((_k = restrictions === null || restrictions === void 0 ? void 0 : restrictions.volume) === null || _k === void 0 ? void 0 : _k.min)
3848
+ || ((_l = restrictions === null || restrictions === void 0 ? void 0 : restrictions.volume) === null || _l === void 0 ? void 0 : _l.max) != undefined && dimensions.height * dimensions.width > ((_m = restrictions === null || restrictions === void 0 ? void 0 : restrictions.volume) === null || _m === void 0 ? void 0 : _m.max);
3729
3849
  };
3730
3850
  return AbstractInteractiveCanvas;
3731
3851
  }());
@@ -3737,7 +3857,11 @@ var SelectionData = /** @class */ (function () {
3737
3857
  this.isText = selectedObject
3738
3858
  && selectedObject.getType() === exports.ObjectType.TEXT
3739
3859
  && selectedObject.isEditing();
3860
+ this.event = {};
3740
3861
  }
3862
+ SelectionData.prototype.setEvent = function (event) {
3863
+ this.event = event;
3864
+ };
3741
3865
  return SelectionData;
3742
3866
  }());
3743
3867
 
@@ -3849,9 +3973,9 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3849
3973
  _this.headless = false;
3850
3974
  _this.undoStack = new UndoStack(_this);
3851
3975
  //Initialize watchers
3852
- _this.fabricCanvas.on("selection:updated", function () { return _this.onFabricSelectionChanged(); });
3853
- _this.fabricCanvas.on("selection:created", function () { return _this.onFabricSelectionChanged(); });
3854
- _this.fabricCanvas.on("selection:cleared", function () { return _this.onFabricSelectionChanged(); });
3976
+ _this.fabricCanvas.on("selection:updated", function (event) { return _this.onFabricSelectionChanged(event); });
3977
+ _this.fabricCanvas.on("selection:created", function (event) { return _this.onFabricSelectionChanged(event); });
3978
+ _this.fabricCanvas.on("selection:cleared", function (event) { return _this.onFabricSelectionChanged(event); });
3855
3979
  _this.fabricCanvas.on("text:editing:entered", function () { return _this.onTextEditing(); });
3856
3980
  _this.fabricCanvas.on("text:editing:exited", function () { return _this.onTextEditing(); });
3857
3981
  _this.fabricCanvas.on("text:changed", function () { return _this.onTextChange(); });
@@ -3896,9 +4020,11 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3896
4020
  });
3897
4021
  });
3898
4022
  };
3899
- InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
4023
+ InteractiveCanvas.prototype.onFabricSelectionChanged = function (event) {
3900
4024
  var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
3901
- this.selection$.next(new SelectionData(selected));
4025
+ var selection = new SelectionData(selected);
4026
+ selection.setEvent(event);
4027
+ this.selection$.next(selection);
3902
4028
  this.enterTextSelectionModeIfRequired();
3903
4029
  };
3904
4030
  InteractiveCanvas.prototype.enterTextSelectionModeIfRequired = function () {
@@ -3916,82 +4042,6 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3916
4042
  return InteractiveCanvas;
3917
4043
  }(AbstractInteractiveCanvas));
3918
4044
 
3919
- var RepositionCutoffsLayoutFunction = /** @class */ (function () {
3920
- function RepositionCutoffsLayoutFunction() {
3921
- }
3922
- RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
3923
- canvas.getObjectsByTypeInternal(exports.ObjectType.CUTOFF)
3924
- .forEach(function (cutoff) { return cutoff.updatePosition(); });
3925
- };
3926
- return RepositionCutoffsLayoutFunction;
3927
- }());
3928
-
3929
- var PinToBottomLayoutFunction = /** @class */ (function () {
3930
- function PinToBottomLayoutFunction() {
3931
- }
3932
- PinToBottomLayoutFunction.prototype.execute = function (canvas) {
3933
- canvas.getObjectsInternal()
3934
- .forEach(function (object) { return object.moveToPinnedPosition(); });
3935
- };
3936
- return PinToBottomLayoutFunction;
3937
- }());
3938
-
3939
- var ResizeCanvasLayoutFunction = /** @class */ (function () {
3940
- function ResizeCanvasLayoutFunction() {
3941
- }
3942
- ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
3943
- if (canvas.getLayoutManager().isEnforcedPositioning)
3944
- return;
3945
- if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
3946
- return;
3947
- var currentDimensions = canvas.getDimensions();
3948
- var baseDimensions = canvas.getBaseDimensions();
3949
- var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
3950
- .filter(function (text) { return text.isResizeCanvas(); })
3951
- .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
3952
- var increase = baseDimensions.withSize(currentDimensions.width, 0);
3953
- while (increase.heightPx < textHeightIncreasePx) {
3954
- increase = increase.withSize(increase.width, increase.height + 1);
3955
- }
3956
- var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
3957
- if (currentDimensions.height !== targetHeight.height) {
3958
- canvas.setDimensions(targetHeight);
3959
- }
3960
- canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
3961
- canvas.redraw();
3962
- };
3963
- return ResizeCanvasLayoutFunction;
3964
- }());
3965
-
3966
- var AdvancedLayoutManager = /** @class */ (function (_super) {
3967
- __extends(AdvancedLayoutManager, _super);
3968
- function AdvancedLayoutManager(canvas) {
3969
- var _this = _super.call(this, canvas) || this;
3970
- _this.key = exports.LayoutManager.ADVANCED;
3971
- _this.pinToBottom = new PinToBottomLayoutFunction();
3972
- _this.redrawAll = new RedrawAllLayoutFunction();
3973
- _this.repositionBorders = new RepositionBordersLayoutFunction();
3974
- _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
3975
- _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
3976
- _this.resizeCanvas = new ResizeCanvasLayoutFunction();
3977
- return _this;
3978
- }
3979
- AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
3980
- this.pinToBottom.execute(this.canvas);
3981
- this.repositionCutoffs.execute(this.canvas);
3982
- this.repositionBorders.execute(this.canvas);
3983
- this.repositionBackgrounds.execute(this.canvas);
3984
- this.redrawAll.execute(this.canvas);
3985
- };
3986
- AdvancedLayoutManager.prototype.onTextChange = function () {
3987
- this.resizeCanvas.execute(this.canvas);
3988
- };
3989
- AdvancedLayoutManager.prototype.onObjectListChange = function () {
3990
- this.redrawAll.execute(this.canvas);
3991
- };
3992
- return AdvancedLayoutManager;
3993
- }(AbstractLayoutManager));
3994
-
3995
4045
  exports.AbstractCanvasObject = AbstractCanvasObject;
3996
4046
  exports.AbstractInteractiveCanvas = AbstractInteractiveCanvas;
3997
4047
  exports.AbstractLayoutManager = AbstractLayoutManager;