@leapfrog/interactive-canvas 2.0.17-beta-2 → 2.0.18

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.
@@ -1,27 +1,29 @@
1
- import _, { round, each, values, reduce, clone, isEqual } from 'lodash';
1
+ import * as _ from 'lodash';
2
+ import { round, each, values, reduce, clone, replace, find, isEqual } from 'lodash';
3
+ import { oc } from 'ts-optchain';
2
4
  import { BehaviorSubject, Subject } from 'rxjs';
3
5
  import { fabric } from 'fabric';
4
6
 
5
- var PIXELS_PER_MM$2 = 3.937;
7
+ var PIXELS_PER_MM = 3.937;
6
8
  var MillimeterDimensions = /** @class */ (function () {
7
9
  function MillimeterDimensions(width, height) {
8
10
  this.widthUnit = "mm";
9
11
  this.heightUnit = "mm";
10
12
  this.width = width;
11
13
  this.widthMm = Math.max(0, width);
12
- this.widthPx = round(this.widthMm * PIXELS_PER_MM$2);
14
+ this.widthPx = round(this.widthMm * PIXELS_PER_MM);
13
15
  this.height = height;
14
16
  this.heightMm = Math.max(0, height);
15
- this.heightPx = round(this.heightMm * PIXELS_PER_MM$2);
17
+ this.heightPx = round(this.heightMm * PIXELS_PER_MM);
16
18
  }
17
19
  MillimeterDimensions.prototype.withSize = function (width, height) {
18
20
  return new MillimeterDimensions(width, height);
19
21
  };
20
22
  MillimeterDimensions.prototype.widthPxToMm = function (px) {
21
- return px / PIXELS_PER_MM$2;
23
+ return px / PIXELS_PER_MM;
22
24
  };
23
25
  MillimeterDimensions.prototype.heightPxToMm = function (px) {
24
- return px / PIXELS_PER_MM$2;
26
+ return px / PIXELS_PER_MM;
25
27
  };
26
28
  return MillimeterDimensions;
27
29
  }());
@@ -47,8 +49,8 @@ var PixelCanvasDimensions = /** @class */ (function () {
47
49
  return PixelCanvasDimensions;
48
50
  }());
49
51
 
50
- var COLUMN_WIDTH_MM$1 = 41;
51
- var GUTTER_WIDTH_MM$1 = 3;
52
+ var COLUMN_WIDTH_MM = 41;
53
+ var GUTTER_WIDTH_MM = 3;
52
54
  var PIXELS_PER_MM$1 = 3.937;
53
55
  var Print6ColCanvasDimensions = /** @class */ (function () {
54
56
  function Print6ColCanvasDimensions(width, height) {
@@ -56,8 +58,8 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
56
58
  this.heightUnit = "cm";
57
59
  this.width = width;
58
60
  this.gutterCount = Math.max(0, width - 1);
59
- this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
60
- this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
61
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
62
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM;
61
63
  this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
62
64
  this.widthPx = round(this.widthMm * PIXELS_PER_MM$1);
63
65
  this.height = height;
@@ -76,119 +78,110 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
76
78
  return Print6ColCanvasDimensions;
77
79
  }());
78
80
 
79
- var COLUMN_WIDTH_MM = 30.8772;
80
- var GUTTER_WIDTH_MM = 2.1053;
81
- var PIXELS_PER_MM = 3.937;
81
+ var COLUMN_WIDTH_MM$1 = 30.8772;
82
+ var GUTTER_WIDTH_MM$1 = 2.1053;
83
+ var PIXELS_PER_MM$2 = 3.937;
82
84
  var Print8ColCanvasDimensions = /** @class */ (function () {
83
85
  function Print8ColCanvasDimensions(width, height) {
84
86
  this.widthUnit = "column(s)";
85
87
  this.heightUnit = "cm";
86
88
  this.width = width;
87
89
  this.gutterCount = Math.max(0, width - 1);
88
- this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
89
- this.columnsTotalMm = width * COLUMN_WIDTH_MM;
90
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
91
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
90
92
  this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
91
- this.widthPx = round(this.widthMm * PIXELS_PER_MM);
93
+ this.widthPx = round(this.widthMm * PIXELS_PER_MM$2);
92
94
  this.height = height;
93
95
  this.heightMm = Math.max(0, height * 10);
94
- this.heightPx = round(this.heightMm * PIXELS_PER_MM);
96
+ this.heightPx = round(this.heightMm * PIXELS_PER_MM$2);
95
97
  }
96
98
  Print8ColCanvasDimensions.prototype.withSize = function (width, height) {
97
99
  return new Print8ColCanvasDimensions(width, height);
98
100
  };
99
101
  Print8ColCanvasDimensions.prototype.widthPxToMm = function (px) {
100
- return px / PIXELS_PER_MM;
102
+ return px / PIXELS_PER_MM$2;
101
103
  };
102
104
  Print8ColCanvasDimensions.prototype.heightPxToMm = function (px) {
103
- return px / PIXELS_PER_MM;
105
+ return px / PIXELS_PER_MM$2;
104
106
  };
105
107
  return Print8ColCanvasDimensions;
106
108
  }());
107
109
 
108
- /******************************************************************************
109
- Copyright (c) Microsoft Corporation.
110
-
111
- Permission to use, copy, modify, and/or distribute this software for any
112
- purpose with or without fee is hereby granted.
113
-
114
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
115
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
116
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
117
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
118
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
119
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
120
- PERFORMANCE OF THIS SOFTWARE.
121
- ***************************************************************************** */
122
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
123
-
124
- var extendStatics = function(d, b) {
125
- extendStatics = Object.setPrototypeOf ||
126
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
127
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
128
- return extendStatics(d, b);
129
- };
130
-
131
- function __extends(d, b) {
132
- if (typeof b !== "function" && b !== null)
133
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
134
- extendStatics(d, b);
135
- function __() { this.constructor = d; }
136
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
137
- }
138
-
139
- function __awaiter(thisArg, _arguments, P, generator) {
140
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
141
- return new (P || (P = Promise))(function (resolve, reject) {
142
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
143
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
144
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
145
- step((generator = generator.apply(thisArg, _arguments || [])).next());
146
- });
147
- }
148
-
149
- function __generator(thisArg, body) {
150
- 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);
151
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
152
- function verb(n) { return function (v) { return step([n, v]); }; }
153
- function step(op) {
154
- if (f) throw new TypeError("Generator is already executing.");
155
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
156
- 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;
157
- if (y = 0, t) op = [op[0] & 2, t.value];
158
- switch (op[0]) {
159
- case 0: case 1: t = op; break;
160
- case 4: _.label++; return { value: op[1], done: false };
161
- case 5: _.label++; y = op[1]; op = [0]; continue;
162
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
163
- default:
164
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
165
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
166
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
167
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
168
- if (t[2]) _.ops.pop();
169
- _.trys.pop(); continue;
170
- }
171
- op = body.call(thisArg, _);
172
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
173
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
174
- }
175
- }
176
-
177
- function __spreadArray(to, from, pack) {
178
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
179
- if (ar || !(i in from)) {
180
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
181
- ar[i] = from[i];
182
- }
183
- }
184
- return to.concat(ar || Array.prototype.slice.call(from));
185
- }
186
-
187
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
188
- var e = new Error(message);
189
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
110
+ /*! *****************************************************************************
111
+ Copyright (c) Microsoft Corporation.
112
+
113
+ Permission to use, copy, modify, and/or distribute this software for any
114
+ purpose with or without fee is hereby granted.
115
+
116
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
117
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
118
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
119
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
120
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
121
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
122
+ PERFORMANCE OF THIS SOFTWARE.
123
+ ***************************************************************************** */
124
+ /* global Reflect, Promise */
125
+
126
+ var extendStatics = function(d, b) {
127
+ extendStatics = Object.setPrototypeOf ||
128
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
129
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
130
+ return extendStatics(d, b);
190
131
  };
191
132
 
133
+ function __extends(d, b) {
134
+ extendStatics(d, b);
135
+ function __() { this.constructor = d; }
136
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
137
+ }
138
+
139
+ function __awaiter(thisArg, _arguments, P, generator) {
140
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
141
+ return new (P || (P = Promise))(function (resolve, reject) {
142
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
143
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
144
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
145
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
146
+ });
147
+ }
148
+
149
+ function __generator(thisArg, body) {
150
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
151
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
152
+ function verb(n) { return function (v) { return step([n, v]); }; }
153
+ function step(op) {
154
+ if (f) throw new TypeError("Generator is already executing.");
155
+ while (_) try {
156
+ 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;
157
+ if (y = 0, t) op = [op[0] & 2, t.value];
158
+ switch (op[0]) {
159
+ case 0: case 1: t = op; break;
160
+ case 4: _.label++; return { value: op[1], done: false };
161
+ case 5: _.label++; y = op[1]; op = [0]; continue;
162
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
163
+ default:
164
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
165
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
166
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
167
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
168
+ if (t[2]) _.ops.pop();
169
+ _.trys.pop(); continue;
170
+ }
171
+ op = body.call(thisArg, _);
172
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
173
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
174
+ }
175
+ }
176
+
177
+ function __spreadArrays() {
178
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
179
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
180
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
181
+ r[k] = a[j];
182
+ return r;
183
+ }
184
+
192
185
  var Font = /** @class */ (function () {
193
186
  function Font() {
194
187
  }
@@ -291,64 +284,6 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
291
284
  return RedrawAllLayoutFunction;
292
285
  }());
293
286
 
294
- var RepositionCutoffsLayoutFunction = /** @class */ (function () {
295
- function RepositionCutoffsLayoutFunction() {
296
- }
297
- RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
298
- canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
299
- .forEach(function (cutoff) { return cutoff.updatePosition(); });
300
- };
301
- return RepositionCutoffsLayoutFunction;
302
- }());
303
-
304
- var RepositionBordersLayoutFunction = /** @class */ (function () {
305
- function RepositionBordersLayoutFunction() {
306
- }
307
- RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
308
- canvas.getObjectsByTypeInternal(ObjectType.BORDER)
309
- .forEach(function (border) { return border.updatePosition(); });
310
- };
311
- return RepositionBordersLayoutFunction;
312
- }());
313
-
314
- var PinToBottomLayoutFunction = /** @class */ (function () {
315
- function PinToBottomLayoutFunction() {
316
- }
317
- PinToBottomLayoutFunction.prototype.execute = function (canvas) {
318
- canvas.getObjectsInternal()
319
- .forEach(function (object) { return object.moveToPinnedPosition(); });
320
- };
321
- return PinToBottomLayoutFunction;
322
- }());
323
-
324
- var ResizeCanvasLayoutFunction = /** @class */ (function () {
325
- function ResizeCanvasLayoutFunction() {
326
- }
327
- ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
328
- var _a, _b;
329
- if (canvas.getLayoutManager().isEnforcedPositioning)
330
- return;
331
- 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)
332
- return;
333
- var currentDimensions = canvas.getDimensions();
334
- var baseDimensions = canvas.getBaseDimensions();
335
- var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
336
- .filter(function (text) { return text.isResizeCanvas(); })
337
- .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
338
- var increase = baseDimensions.withSize(currentDimensions.width, 0);
339
- while (increase.heightPx < textHeightIncreasePx) {
340
- increase = increase.withSize(increase.width, increase.height + 1);
341
- }
342
- var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
343
- if (currentDimensions.height !== targetHeight.height) {
344
- canvas.setDimensions(targetHeight);
345
- }
346
- canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
347
- canvas.redraw();
348
- };
349
- return ResizeCanvasLayoutFunction;
350
- }());
351
-
352
287
  var LayoutManager;
353
288
  (function (LayoutManager) {
354
289
  LayoutManager["LEGACY"] = "LEGACY";
@@ -356,45 +291,6 @@ var LayoutManager;
356
291
  LayoutManager["ADVANCED"] = "ADVANCED";
357
292
  })(LayoutManager || (LayoutManager = {}));
358
293
 
359
- var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
360
- function RepositionBackgroundsLayoutFunction() {
361
- }
362
- RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
363
- canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
364
- .forEach(function (border) { return border.updatePosition(); });
365
- };
366
- return RepositionBackgroundsLayoutFunction;
367
- }());
368
-
369
- var AdvancedLayoutManager = /** @class */ (function (_super) {
370
- __extends(AdvancedLayoutManager, _super);
371
- function AdvancedLayoutManager(canvas) {
372
- var _this = _super.call(this, canvas) || this;
373
- _this.key = LayoutManager.ADVANCED;
374
- _this.pinToBottom = new PinToBottomLayoutFunction();
375
- _this.redrawAll = new RedrawAllLayoutFunction();
376
- _this.repositionBorders = new RepositionBordersLayoutFunction();
377
- _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
378
- _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
379
- _this.resizeCanvas = new ResizeCanvasLayoutFunction();
380
- return _this;
381
- }
382
- AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
383
- this.pinToBottom.execute(this.canvas);
384
- this.repositionCutoffs.execute(this.canvas);
385
- this.repositionBorders.execute(this.canvas);
386
- this.repositionBackgrounds.execute(this.canvas);
387
- this.redrawAll.execute(this.canvas);
388
- };
389
- AdvancedLayoutManager.prototype.onTextChange = function () {
390
- this.resizeCanvas.execute(this.canvas);
391
- };
392
- AdvancedLayoutManager.prototype.onObjectListChange = function () {
393
- this.redrawAll.execute(this.canvas);
394
- };
395
- return AdvancedLayoutManager;
396
- }(AbstractLayoutManager));
397
-
398
294
  var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
399
295
  function UpdateObjectDimensionsLayoutFunction() {
400
296
  }
@@ -436,14 +332,13 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
436
332
  var currentColumnWidthPercent = 0;
437
333
  each(footerRows.rows, function (row) {
438
334
  each(row.objects, function (object) {
439
- var _a, _b, _c;
440
335
  var columnOffset = currentColumnWidthPercent / 100 * layoutAreaWidth;
441
- 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;
336
+ var objectMargin = oc(object.getMargin()).left(0);
442
337
  var left = canvasMargin.left + columnOffset + objectMargin;
443
338
  if (object.getType() === ObjectType.VERTICAL_RULE)
444
339
  object.setPosition({ height: row.height });
445
340
  object.setPosition({
446
- top: nextObjectTop + ((_c = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _c === void 0 ? void 0 : _c.top) || 0,
341
+ top: nextObjectTop + oc(object.getMargin()).top(0),
447
342
  left: left
448
343
  });
449
344
  currentColumnWidthPercent += object.getColumnWidthPercent();
@@ -453,7 +348,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
453
348
  });
454
349
  };
455
350
  StackObjectsLayoutFunction.prototype.layoutBody = function (bodyRows, canvas, footerHeight) {
456
- var _a, _b, _c, _d;
457
351
  var canvasDimensions = canvas.getDimensions();
458
352
  var canvasMargin = canvas.getMargin();
459
353
  var workableWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
@@ -466,10 +360,10 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
466
360
  for (var i = 0; i < bodyRows.rows.length; i++) {
467
361
  var row = bodyRows.rows[i];
468
362
  var nextRow = bodyRows.rows[i + 1];
469
- for (var _i = 0, _e = row.objects; _i < _e.length; _i++) {
470
- var object = _e[_i];
363
+ for (var _i = 0, _a = row.objects; _i < _a.length; _i++) {
364
+ var object = _a[_i];
471
365
  var columnOffset = currentColumnWidthPercent / 100 * workableWidth;
472
- var objectMargin = (_a = object.getMargin().left) !== null && _a !== void 0 ? _a : 0;
366
+ var objectMargin = oc(object.getMargin()).left(0);
473
367
  var objectLeft = canvasMargin.left + columnOffset + objectMargin;
474
368
  if (object.getType() === ObjectType.TEXT && object.isBulleted())
475
369
  objectLeft += object.getBulletMargin();
@@ -478,7 +372,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
478
372
  if (object.getType() === ObjectType.VERTICAL_RULE)
479
373
  return;
480
374
  object.setPosition({
481
- top: nextObjectTop + ((_b = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _b === void 0 ? void 0 : _b.top) || 0,
375
+ top: nextObjectTop + oc(object.getMargin()).top(0),
482
376
  left: objectLeft
483
377
  });
484
378
  currentColumnWidthPercent += object.getColumnWidthPercent();
@@ -486,7 +380,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
486
380
  currentColumnWidthPercent = 0;
487
381
  nextObjectTop += row.height;
488
382
  var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === ObjectType.HORIZONTAL_RULE;
489
- 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()) === ObjectType.HORIZONTAL_RULE;
383
+ var nextRowIsHR = oc(nextRow).objects.length() === 1 && oc(nextRow).objects()[0].getType() === ObjectType.HORIZONTAL_RULE;
490
384
  if (!thisRowIsHR && !nextRowIsHR) {
491
385
  nextObjectTop += spaceSize;
492
386
  }
@@ -494,9 +388,8 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
494
388
  };
495
389
  StackObjectsLayoutFunction.prototype.applyWidths = function (objects, layoutWidth) {
496
390
  _(objects).forEach(function (object) {
497
- var _a, _b;
498
391
  var targetWidth = object.getColumnWidthPercent() / 100 * layoutWidth;
499
- 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);
392
+ var actualWidth = targetWidth - oc(object.getMargin()).left(0) - oc(object.getMargin()).right(0);
500
393
  if (object.getType() === ObjectType.VERTICAL_RULE)
501
394
  return;
502
395
  if (object.getType() === ObjectType.TEXT && object.isBulleted())
@@ -510,11 +403,10 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
510
403
  });
511
404
  };
512
405
  StackObjectsLayoutFunction.prototype.adjustCanvasSize = function (canvas, requiredHeight) {
513
- var _a, _b, _c, _d;
514
- if ((_a = canvas === null || canvas === void 0 ? void 0 : canvas.getDimensionsRestrictions()) === null || _a === void 0 ? void 0 : _a.fixed)
406
+ if (oc(canvas.getDimensionsRestrictions()).fixed(false))
515
407
  return;
516
408
  var dimensions = canvas.getDimensions();
517
- 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;
409
+ var minHeight = oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
518
410
  var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
519
411
  while (targetDimensions.heightPx < requiredHeight) {
520
412
  targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
@@ -547,19 +439,17 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
547
439
  return result;
548
440
  };
549
441
  StackObjectsLayoutFunction.prototype.getObjectHeight = function (element) {
550
- var _a, _b;
551
442
  return element.getBoundingBox().height
552
- + (((_a = element === null || element === void 0 ? void 0 : element.getMargin()) === null || _a === void 0 ? void 0 : _a.top) || 0)
553
- + (((_b = element === null || element === void 0 ? void 0 : element.getMargin()) === null || _b === void 0 ? void 0 : _b.bottom) || 0);
443
+ + oc(element.getMargin()).top(0)
444
+ + oc(element.getMargin()).bottom(0);
554
445
  };
555
446
  StackObjectsLayoutFunction.prototype.countSpaces = function (rows) {
556
- var _a, _b;
557
447
  var count = 0;
558
448
  for (var i = 0; i < rows.rows.length - 1; i++) {
559
449
  var row = rows.rows[i];
560
450
  var nextRow = rows.rows[i + 1];
561
451
  var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === ObjectType.HORIZONTAL_RULE;
562
- 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()) === ObjectType.HORIZONTAL_RULE;
452
+ var nextRowIsHR = oc(nextRow).objects.length() === 1 && oc(nextRow).objects()[0].getType() === ObjectType.HORIZONTAL_RULE;
563
453
  if (!thisRowIsHR && !nextRowIsHR) {
564
454
  count++;
565
455
  }
@@ -569,6 +459,26 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
569
459
  return StackObjectsLayoutFunction;
570
460
  }());
571
461
 
462
+ var RepositionBordersLayoutFunction = /** @class */ (function () {
463
+ function RepositionBordersLayoutFunction() {
464
+ }
465
+ RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
466
+ canvas.getObjectsByTypeInternal(ObjectType.BORDER)
467
+ .forEach(function (border) { return border.updatePosition(); });
468
+ };
469
+ return RepositionBordersLayoutFunction;
470
+ }());
471
+
472
+ var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
473
+ function RepositionBackgroundsLayoutFunction() {
474
+ }
475
+ RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
476
+ canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
477
+ .forEach(function (border) { return border.updatePosition(); });
478
+ };
479
+ return RepositionBackgroundsLayoutFunction;
480
+ }());
481
+
572
482
  var StandardLayoutManager = /** @class */ (function (_super) {
573
483
  __extends(StandardLayoutManager, _super);
574
484
  function StandardLayoutManager(canvas) {
@@ -801,15 +711,14 @@ var AbstractCanvasObject = /** @class */ (function () {
801
711
  * @inheritDoc
802
712
  */
803
713
  AbstractCanvasObject.prototype.setMargin = function (margin) {
804
- var _a, _b;
805
714
  if (!margin)
806
715
  return;
807
- var newMargin = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.margin) !== null && _b !== void 0 ? _b : {
716
+ var newMargin = oc(this.data).margin({
808
717
  top: 0,
809
718
  right: 0,
810
719
  bottom: 0,
811
720
  left: 0
812
- };
721
+ });
813
722
  if (margin.top != undefined)
814
723
  newMargin.top = margin.top || 0;
815
724
  if (margin.right != undefined)
@@ -826,8 +735,7 @@ var AbstractCanvasObject = /** @class */ (function () {
826
735
  * @inheritDoc
827
736
  */
828
737
  AbstractCanvasObject.prototype.getColumnWidthPercent = function () {
829
- var _a, _b;
830
- 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);
738
+ return Math.max(Math.min(oc(this.data).columnWidthPercent(100), 100), 0);
831
739
  };
832
740
  /**
833
741
  * @override
@@ -1909,20 +1817,6 @@ var RichText = /** @class */ (function (_super) {
1909
1817
  return RichText;
1910
1818
  }(Image));
1911
1819
 
1912
- var ObjectType;
1913
- (function (ObjectType) {
1914
- ObjectType["TEXT"] = "TEXT";
1915
- ObjectType["BORDER"] = "BORDER";
1916
- ObjectType["IMAGE"] = "IMAGE";
1917
- ObjectType["RECTANGLE"] = "RECTANGLE";
1918
- ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
1919
- ObjectType["CUTOFF"] = "CUTOFF";
1920
- ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
1921
- ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
1922
- ObjectType["RICH_TEXT"] = "RICH_TEXT";
1923
- ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
1924
- })(ObjectType || (ObjectType = {}));
1925
-
1926
1820
  var Text = /** @class */ (function (_super) {
1927
1821
  __extends(Text, _super);
1928
1822
  function Text(canvas, fabricObject, persistedField) {
@@ -1976,21 +1870,6 @@ var Text = /** @class */ (function (_super) {
1976
1870
  this.data.userText = this.fabricObject.text;
1977
1871
  this.text$.next(this.fabricObject.text);
1978
1872
  };
1979
- Text.prototype.replaceTextWithStyle = function (target, replacement) {
1980
- var start = this.getText().indexOf(target);
1981
- var styles = this.getReplacementStyle(target, replacement);
1982
- this.fabricObject.insertChars(replacement, styles, start, start + target.length);
1983
- this.redraw();
1984
- this.data.userText = this.fabricObject.text;
1985
- this.text$.next(this.fabricObject.text);
1986
- };
1987
- Text.prototype.getReplacementStyle = function (target, replacement) {
1988
- var start = this.getText().indexOf(target);
1989
- var lineIndex = (this.getText().substring(0, start).split(Text.NEW_LINE).length - 1);
1990
- var lines = this.getText().split(Text.NEW_LINE);
1991
- var startWithinLine = lines[lineIndex].indexOf(target);
1992
- return Array(replacement.length).fill(this.fabricObject.styles[lineIndex][startWithinLine]);
1993
- };
1994
1873
  /**
1995
1874
  * @override
1996
1875
  * @inheritDoc
@@ -2105,7 +1984,7 @@ var Text = /** @class */ (function (_super) {
2105
1984
  Text.prototype.setBoldRegion = function (start, end, bold) {
2106
1985
  if (bold === void 0) { bold = true; }
2107
1986
  if (start > end)
2108
- throw Error("Bad region specified: [".concat(start, " - ").concat(end, "]"));
1987
+ throw Error("Bad region specified: [" + start + " - " + end + "]");
2109
1988
  for (var i = start; i < end; i++) {
2110
1989
  var style = this.fabricObject.getStyleAtPosition(i, true);
2111
1990
  var font = this.fontLibrary.getFont(style.fontFamily);
@@ -2136,7 +2015,7 @@ var Text = /** @class */ (function (_super) {
2136
2015
  Text.prototype.setItalicRegion = function (start, end, italic) {
2137
2016
  if (italic === void 0) { italic = true; }
2138
2017
  if (start > end)
2139
- throw Error("Bad region specified: [".concat(start, " - ").concat(end, "]"));
2018
+ throw Error("Bad region specified: [" + start + " - " + end + "]");
2140
2019
  this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" }, start, end);
2141
2020
  this.redraw();
2142
2021
  };
@@ -2287,7 +2166,7 @@ var Text = /** @class */ (function (_super) {
2287
2166
  if (!this.isBulleted())
2288
2167
  return 0;
2289
2168
  var fontSize = 0;
2290
- _.each(this.fabricObject._textLines, function (textLine, lineIndex) {
2169
+ each(this.fabricObject._textLines, function (textLine, lineIndex) {
2291
2170
  fontSize = Math.max(fontSize, _this_1.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
2292
2171
  });
2293
2172
  return fontSize * 0.6;
@@ -2366,10 +2245,9 @@ var Text = /** @class */ (function (_super) {
2366
2245
  * @inheritDoc
2367
2246
  */
2368
2247
  Text.prototype.enableBullets = function () {
2369
- var _a;
2370
2248
  this.disableOrderedList();
2371
2249
  this.fabricObject["objectCaching"] = false;
2372
- this.fabricObject["_bullets"] = (_a = this.fabricObject["_bullets"]) !== null && _a !== void 0 ? _a : {};
2250
+ this.fabricObject["_bullets"] = this.fabricObject["_bullets"] || {};
2373
2251
  this.data.bulleted = true;
2374
2252
  this.notifyCanvasOfTextChanges();
2375
2253
  this.redraw();
@@ -2436,7 +2314,7 @@ var Text = /** @class */ (function (_super) {
2436
2314
  if (this.data.bulleted) {
2437
2315
  var bullets = this.fabricObject["_bullets"];
2438
2316
  delete this.fabricObject["_bullets"];
2439
- _.each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2317
+ each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2440
2318
  this.fabricObject["objectCaching"] = true;
2441
2319
  }
2442
2320
  };
@@ -2445,7 +2323,7 @@ var Text = /** @class */ (function (_super) {
2445
2323
  if (this.fabricObject._isOrderedList) {
2446
2324
  var markerEntities = this.fabricObject._orderedListMarkerEntities;
2447
2325
  delete this.fabricObject._orderedListMarkerEntities;
2448
- _.each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2326
+ each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2449
2327
  this.fabricObject["objectCaching"] = true;
2450
2328
  }
2451
2329
  };
@@ -2458,13 +2336,12 @@ var Text = /** @class */ (function (_super) {
2458
2336
  var originalRender = this.fabricObject["_render"];
2459
2337
  var fabric = this.canvas.fabric;
2460
2338
  this.fabricObject["_render"] = function (ctx) {
2461
- var _a;
2462
2339
  var fabricText = this;
2463
2340
  if (fabricText["_bullets"]) {
2464
2341
  // Determine list of active bullets
2465
2342
  var currentBullets_1 = fabricText["_bullets"];
2466
2343
  var activeBullets_1 = {};
2467
- _.each(fabricText._textLines, function (textLine, lineIndex) {
2344
+ each(fabricText._textLines, function (textLine, lineIndex) {
2468
2345
  if (textLine.length) {
2469
2346
  // Start of real lines will have offset 0 in styleMap
2470
2347
  var styleMap = fabricText._styleMap[lineIndex];
@@ -2498,13 +2375,13 @@ var Text = /** @class */ (function (_super) {
2498
2375
  var canvas_1 = fabricText.canvas;
2499
2376
  var canvasDirty_1 = false;
2500
2377
  canvas_1.renderOnAddRemove = false;
2501
- _.each(activeBullets_1, function (bullet) {
2378
+ each(activeBullets_1, function (bullet) {
2502
2379
  if (!canvas_1.contains(bullet)) {
2503
2380
  canvas_1.add(bullet);
2504
2381
  canvasDirty_1 = true;
2505
2382
  }
2506
2383
  });
2507
- _.each(currentBullets_1, function (bullet, key) {
2384
+ each(currentBullets_1, function (bullet, key) {
2508
2385
  if (!activeBullets_1[key]) {
2509
2386
  canvas_1.remove(bullet);
2510
2387
  canvasDirty_1 = true;
@@ -2518,9 +2395,9 @@ var Text = /** @class */ (function (_super) {
2518
2395
  }
2519
2396
  }
2520
2397
  if (fabricText._isOrderedList) {
2521
- var existingMarkers_1 = (_a = fabricText._orderedListMarkerEntities) !== null && _a !== void 0 ? _a : [];
2398
+ var existingMarkers_1 = fabricText._orderedListMarkerEntities || [];
2522
2399
  var activeMarkers_1 = [];
2523
- _.each(fabricText._textLines, function (textLine, lineIndex) {
2400
+ each(fabricText._textLines, function (textLine, lineIndex) {
2524
2401
  if (textLine.length) {
2525
2402
  // Start of real lines will have offset 0 in styleMap
2526
2403
  var styleMap = fabricText._styleMap[lineIndex];
@@ -2531,7 +2408,7 @@ var Text = /** @class */ (function (_super) {
2531
2408
  }
2532
2409
  else {
2533
2410
  // Create new marker for this line
2534
- var textbox = new fabric.Textbox("".concat(lineIndex, "."), {
2411
+ var textbox = new fabric.Textbox(lineIndex + ".", {
2535
2412
  left: 0,
2536
2413
  top: 0,
2537
2414
  fill: fabricText.fill,
@@ -2553,7 +2430,7 @@ var Text = /** @class */ (function (_super) {
2553
2430
  var canvas_2 = fabricText.canvas;
2554
2431
  var canvasDirty_2 = false;
2555
2432
  canvas_2.renderOnAddRemove = false;
2556
- _.each(activeMarkers_1, function (marker) {
2433
+ each(activeMarkers_1, function (marker) {
2557
2434
  if (!marker)
2558
2435
  return;
2559
2436
  if (!canvas_2.contains(marker)) {
@@ -2561,7 +2438,7 @@ var Text = /** @class */ (function (_super) {
2561
2438
  canvasDirty_2 = true;
2562
2439
  }
2563
2440
  });
2564
- _.each(existingMarkers_1, function (marker, key) {
2441
+ each(existingMarkers_1, function (marker, key) {
2565
2442
  if (!marker)
2566
2443
  return;
2567
2444
  if (!activeMarkers_1[key]) {
@@ -2630,7 +2507,7 @@ var Text = /** @class */ (function (_super) {
2630
2507
  left: fabricText.left + xOffset,
2631
2508
  top: fabricText.top + yOffset,
2632
2509
  angle: fabricText.angle,
2633
- text: "".concat(lineNumber, ".")
2510
+ text: lineNumber + "."
2634
2511
  });
2635
2512
  }
2636
2513
  originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
@@ -2687,7 +2564,6 @@ var Text = /** @class */ (function (_super) {
2687
2564
  Text.prototype.notifyCanvasOfTextChanges = function () {
2688
2565
  this.canvas.notifyTextChanged();
2689
2566
  };
2690
- Text.NEW_LINE = "\n";
2691
2567
  return Text;
2692
2568
  }(AbstractCanvasObject));
2693
2569
  var TextSelection = /** @class */ (function () {
@@ -2850,6 +2726,20 @@ var ImageType;
2850
2726
  ImageType["PHOTO"] = "PHOTO";
2851
2727
  })(ImageType || (ImageType = {}));
2852
2728
 
2729
+ var ObjectType;
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
+ })(ObjectType || (ObjectType = {}));
2742
+
2853
2743
  var AbstractInteractiveCanvas = /** @class */ (function () {
2854
2744
  function AbstractInteractiveCanvas(fabric, fabricCanvas, devicePixelRatio) {
2855
2745
  this.fabric = fabric;
@@ -3031,12 +2921,11 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3031
2921
  * @inheritDoc
3032
2922
  */
3033
2923
  AbstractInteractiveCanvas.prototype.setDimensionRestrictions = function (restrictions) {
3034
- var _a, _b, _c, _d, _e, _f, _g, _h;
3035
2924
  this.dimensionRestrictions$.next(restrictions);
3036
2925
  var dimensions = this.getDimensions();
3037
2926
  if (this.dimensionsExceedRestrictions(dimensions)) {
3038
2927
  var newDimensions = dimensions
3039
- .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)));
2928
+ .withSize(Math.min(Math.max(oc(restrictions).width.min(dimensions.width), dimensions.width), Math.max(oc(restrictions).width.max(dimensions.width))), Math.min(Math.max(oc(restrictions).height.min(dimensions.height), dimensions.height), Math.max(oc(restrictions).height.max(dimensions.height))));
3040
2929
  this.setBaseDimensions(newDimensions);
3041
2930
  }
3042
2931
  };
@@ -3453,7 +3342,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3453
3342
  var objectsToLayout = _(this.getObjectsByTypesInternal(ObjectType.TEXT, ObjectType.IMAGE))
3454
3343
  .sortBy(function (x) { return x.getBoundingBox().top; })
3455
3344
  .value();
3456
- var objectsHeight = _.reduce(objectsToLayout, function (total, element) { return total + element.getBoundingBox().height; }, 0);
3345
+ var objectsHeight = reduce(objectsToLayout, function (total, element) { return total + element.getBoundingBox().height; }, 0);
3457
3346
  var workableHeight = canvasHeight - margin.top - margin.bottom;
3458
3347
  var requiredPadding = workableHeight - objectsHeight;
3459
3348
  var spaceBetween = requiredPadding / (objectsToLayout.length - 1);
@@ -3627,7 +3516,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3627
3516
  if (activeObject) {
3628
3517
  this.fabricCanvas.setActiveObject(activeObject);
3629
3518
  }
3630
- return _.replace(base64, /^data:.*;base64,/, "");
3519
+ return replace(base64, /^data:.*;base64,/, "");
3631
3520
  };
3632
3521
  /**
3633
3522
  * @override
@@ -3749,20 +3638,20 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3749
3638
  case ObjectType.BACKGROUND_IMAGE:
3750
3639
  return new BackgroundImage(this, fabricObject, persistedField);
3751
3640
  default:
3752
- throw new Error("Unknown field type: [".concat(persistedField.type, "]"));
3641
+ throw new Error("Unknown field type: [" + persistedField.type + "]");
3753
3642
  }
3754
3643
  };
3755
3644
  AbstractInteractiveCanvas.prototype.findFabricObject = function (id) {
3756
3645
  var objects = this.fabricCanvas.getObjects();
3757
- var fabricObject = _.find(objects, function (o) { return o.id == id; });
3646
+ var fabricObject = find(objects, function (o) { return o.id == id; });
3758
3647
  if (!fabricObject) {
3759
- throw new Error("Cannot find fabric object with id [".concat(id, "]"));
3648
+ throw new Error("Cannot find fabric object with id [" + id + "]");
3760
3649
  }
3761
3650
  return fabricObject;
3762
3651
  };
3763
3652
  AbstractInteractiveCanvas.prototype.findObject = function (id) {
3764
3653
  //Don't use strict compare here. fabric ids are numbers while ad builder ids are strings... mostly.
3765
- return _.find(this.objects$.value, function (object) { return object.getId() == id; });
3654
+ return find(this.objects$.value, function (object) { return object.getId() == id; });
3766
3655
  };
3767
3656
  /**
3768
3657
  * Reset zoom and canvas dimensions to 1:1 scale, execute a function, then return the canvas to
@@ -3800,7 +3689,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3800
3689
  if (!object) {
3801
3690
  return null;
3802
3691
  }
3803
- return _.find(this.objects$.value, function (field) { return field.getId() == object.id; });
3692
+ return find(this.objects$.value, function (field) { return field.getId() == object.id; });
3804
3693
  };
3805
3694
  AbstractInteractiveCanvas.prototype.getFieldsByCanvasObject = function (objects) {
3806
3695
  var _this = this;
@@ -3812,7 +3701,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3812
3701
  AbstractInteractiveCanvas.prototype.calculateImageCaptureCoefficient = function () {
3813
3702
  var precision = 3;
3814
3703
  var devicePixelRatio = this.devicePixelRatio || 1;
3815
- return _.round(2 / devicePixelRatio, precision);
3704
+ return round(2 / devicePixelRatio, precision);
3816
3705
  };
3817
3706
  AbstractInteractiveCanvas.prototype.randomId = function () {
3818
3707
  var min = 0;
@@ -3827,17 +3716,16 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3827
3716
  .reduce(function (x, y) { return Math.max(x, y); }, 0);
3828
3717
  };
3829
3718
  AbstractInteractiveCanvas.prototype.trackNewObject = function (object) {
3830
- this.objects$.next(__spreadArray(__spreadArray([], this.objects$.value, true), [object], false));
3719
+ this.objects$.next(__spreadArrays(this.objects$.value, [object]));
3831
3720
  };
3832
3721
  AbstractInteractiveCanvas.prototype.dimensionsExceedRestrictions = function (dimensions) {
3833
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
3834
3722
  var restrictions = this.dimensionRestrictions$.value;
3835
- 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)
3836
- || ((_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)
3837
- || ((_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)
3838
- || ((_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)
3839
- || ((_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)
3840
- || ((_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);
3723
+ return oc(restrictions).height.min() != undefined && dimensions.height < oc(restrictions).height.min()
3724
+ || oc(restrictions).height.max() != undefined && dimensions.height > oc(restrictions).height.max()
3725
+ || oc(restrictions).width.min() != undefined && dimensions.width < oc(restrictions).width.min()
3726
+ || oc(restrictions).width.max() != undefined && dimensions.width > oc(restrictions).width.max()
3727
+ || oc(restrictions).volume.min() != undefined && dimensions.height * dimensions.width < oc(restrictions).volume.min()
3728
+ || oc(restrictions).volume.max() != undefined && dimensions.height * dimensions.width > oc(restrictions).volume.max();
3841
3729
  };
3842
3730
  return AbstractInteractiveCanvas;
3843
3731
  }());
@@ -3849,11 +3737,7 @@ var SelectionData = /** @class */ (function () {
3849
3737
  this.isText = selectedObject
3850
3738
  && selectedObject.getType() === ObjectType.TEXT
3851
3739
  && selectedObject.isEditing();
3852
- this.event = {};
3853
3740
  }
3854
- SelectionData.prototype.setEvent = function (event) {
3855
- this.event = event;
3856
- };
3857
3741
  return SelectionData;
3858
3742
  }());
3859
3743
 
@@ -3965,9 +3849,9 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3965
3849
  _this.headless = false;
3966
3850
  _this.undoStack = new UndoStack(_this);
3967
3851
  //Initialize watchers
3968
- _this.fabricCanvas.on("selection:updated", function (event) { return _this.onFabricSelectionChanged(event); });
3969
- _this.fabricCanvas.on("selection:created", function (event) { return _this.onFabricSelectionChanged(event); });
3970
- _this.fabricCanvas.on("selection:cleared", function (event) { return _this.onFabricSelectionChanged(event); });
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(); });
3971
3855
  _this.fabricCanvas.on("text:editing:entered", function () { return _this.onTextEditing(); });
3972
3856
  _this.fabricCanvas.on("text:editing:exited", function () { return _this.onTextEditing(); });
3973
3857
  _this.fabricCanvas.on("text:changed", function () { return _this.onTextChange(); });
@@ -4012,11 +3896,9 @@ var InteractiveCanvas = /** @class */ (function (_super) {
4012
3896
  });
4013
3897
  });
4014
3898
  };
4015
- InteractiveCanvas.prototype.onFabricSelectionChanged = function (event) {
3899
+ InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
4016
3900
  var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
4017
- var selection = new SelectionData(selected);
4018
- selection.setEvent(event);
4019
- this.selection$.next(selection);
3901
+ this.selection$.next(new SelectionData(selected));
4020
3902
  this.enterTextSelectionModeIfRequired();
4021
3903
  };
4022
3904
  InteractiveCanvas.prototype.enterTextSelectionModeIfRequired = function () {
@@ -4034,4 +3916,80 @@ var InteractiveCanvas = /** @class */ (function (_super) {
4034
3916
  return InteractiveCanvas;
4035
3917
  }(AbstractInteractiveCanvas));
4036
3918
 
3919
+ var RepositionCutoffsLayoutFunction = /** @class */ (function () {
3920
+ function RepositionCutoffsLayoutFunction() {
3921
+ }
3922
+ RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
3923
+ canvas.getObjectsByTypeInternal(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 (oc(canvas.getDimensionsRestrictions()).fixed(false))
3946
+ return;
3947
+ var currentDimensions = canvas.getDimensions();
3948
+ var baseDimensions = canvas.getBaseDimensions();
3949
+ var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(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 = 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
+
4037
3995
  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 };