@leapfrog/interactive-canvas 2.0.15 → 2.0.17-beta-1

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,33 +3,30 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _ = require('lodash');
6
+ var tsOptchain = require('ts-optchain');
6
7
  var rxjs = require('rxjs');
7
8
  var fabric = require('fabric');
8
9
 
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;
10
+ var PIXELS_PER_MM = 3.937;
14
11
  var MillimeterDimensions = /** @class */ (function () {
15
12
  function MillimeterDimensions(width, height) {
16
13
  this.widthUnit = "mm";
17
14
  this.heightUnit = "mm";
18
15
  this.width = width;
19
16
  this.widthMm = Math.max(0, width);
20
- this.widthPx = _.round(this.widthMm * PIXELS_PER_MM$2);
17
+ this.widthPx = _.round(this.widthMm * PIXELS_PER_MM);
21
18
  this.height = height;
22
19
  this.heightMm = Math.max(0, height);
23
- this.heightPx = _.round(this.heightMm * PIXELS_PER_MM$2);
20
+ this.heightPx = _.round(this.heightMm * PIXELS_PER_MM);
24
21
  }
25
22
  MillimeterDimensions.prototype.withSize = function (width, height) {
26
23
  return new MillimeterDimensions(width, height);
27
24
  };
28
25
  MillimeterDimensions.prototype.widthPxToMm = function (px) {
29
- return px / PIXELS_PER_MM$2;
26
+ return px / PIXELS_PER_MM;
30
27
  };
31
28
  MillimeterDimensions.prototype.heightPxToMm = function (px) {
32
- return px / PIXELS_PER_MM$2;
29
+ return px / PIXELS_PER_MM;
33
30
  };
34
31
  return MillimeterDimensions;
35
32
  }());
@@ -55,8 +52,8 @@ var PixelCanvasDimensions = /** @class */ (function () {
55
52
  return PixelCanvasDimensions;
56
53
  }());
57
54
 
58
- var COLUMN_WIDTH_MM$1 = 41;
59
- var GUTTER_WIDTH_MM$1 = 3;
55
+ var COLUMN_WIDTH_MM = 41;
56
+ var GUTTER_WIDTH_MM = 3;
60
57
  var PIXELS_PER_MM$1 = 3.937;
61
58
  var Print6ColCanvasDimensions = /** @class */ (function () {
62
59
  function Print6ColCanvasDimensions(width, height) {
@@ -64,8 +61,8 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
64
61
  this.heightUnit = "cm";
65
62
  this.width = width;
66
63
  this.gutterCount = Math.max(0, width - 1);
67
- this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
68
- this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
64
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
65
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM;
69
66
  this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
70
67
  this.widthPx = _.round(this.widthMm * PIXELS_PER_MM$1);
71
68
  this.height = height;
@@ -84,119 +81,110 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
84
81
  return Print6ColCanvasDimensions;
85
82
  }());
86
83
 
87
- var COLUMN_WIDTH_MM = 30.8772;
88
- var GUTTER_WIDTH_MM = 2.1053;
89
- var PIXELS_PER_MM = 3.937;
84
+ var COLUMN_WIDTH_MM$1 = 30.8772;
85
+ var GUTTER_WIDTH_MM$1 = 2.1053;
86
+ var PIXELS_PER_MM$2 = 3.937;
90
87
  var Print8ColCanvasDimensions = /** @class */ (function () {
91
88
  function Print8ColCanvasDimensions(width, height) {
92
89
  this.widthUnit = "column(s)";
93
90
  this.heightUnit = "cm";
94
91
  this.width = width;
95
92
  this.gutterCount = Math.max(0, width - 1);
96
- this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
97
- this.columnsTotalMm = width * COLUMN_WIDTH_MM;
93
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
94
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
98
95
  this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
99
- this.widthPx = _.round(this.widthMm * PIXELS_PER_MM);
96
+ this.widthPx = _.round(this.widthMm * PIXELS_PER_MM$2);
100
97
  this.height = height;
101
98
  this.heightMm = Math.max(0, height * 10);
102
- this.heightPx = _.round(this.heightMm * PIXELS_PER_MM);
99
+ this.heightPx = _.round(this.heightMm * PIXELS_PER_MM$2);
103
100
  }
104
101
  Print8ColCanvasDimensions.prototype.withSize = function (width, height) {
105
102
  return new Print8ColCanvasDimensions(width, height);
106
103
  };
107
104
  Print8ColCanvasDimensions.prototype.widthPxToMm = function (px) {
108
- return px / PIXELS_PER_MM;
105
+ return px / PIXELS_PER_MM$2;
109
106
  };
110
107
  Print8ColCanvasDimensions.prototype.heightPxToMm = function (px) {
111
- return px / PIXELS_PER_MM;
108
+ return px / PIXELS_PER_MM$2;
112
109
  };
113
110
  return Print8ColCanvasDimensions;
114
111
  }());
115
112
 
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;
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);
198
134
  };
199
135
 
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
+
200
188
  var Font = /** @class */ (function () {
201
189
  function Font() {
202
190
  }
@@ -299,110 +287,12 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
299
287
  return RedrawAllLayoutFunction;
300
288
  }());
301
289
 
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;
361
290
  (function (LayoutManager) {
362
291
  LayoutManager["LEGACY"] = "LEGACY";
363
292
  LayoutManager["STANDARD"] = "STANDARD";
364
293
  LayoutManager["ADVANCED"] = "ADVANCED";
365
294
  })(exports.LayoutManager || (exports.LayoutManager = {}));
366
295
 
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
-
406
296
  var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
407
297
  function UpdateObjectDimensionsLayoutFunction() {
408
298
  }
@@ -420,7 +310,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
420
310
  var canvasMargin = canvas.getMargin();
421
311
  var canvasDimensions = canvas.getDimensions();
422
312
  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);
423
- var objects = ___default["default"](allObjects)
313
+ var objects = _(allObjects)
424
314
  .partition(function (object) { return object.isPinToBottom(); })
425
315
  .value();
426
316
  var footerObjects = objects[0];
@@ -444,14 +334,13 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
444
334
  var currentColumnWidthPercent = 0;
445
335
  _.each(footerRows.rows, function (row) {
446
336
  _.each(row.objects, function (object) {
447
- var _a, _b, _c;
448
337
  var columnOffset = currentColumnWidthPercent / 100 * layoutAreaWidth;
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;
338
+ var objectMargin = tsOptchain.oc(object.getMargin()).left(0);
450
339
  var left = canvasMargin.left + columnOffset + objectMargin;
451
340
  if (object.getType() === exports.ObjectType.VERTICAL_RULE)
452
341
  object.setPosition({ height: row.height });
453
342
  object.setPosition({
454
- top: nextObjectTop + ((_c = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _c === void 0 ? void 0 : _c.top) || 0,
343
+ top: nextObjectTop + tsOptchain.oc(object.getMargin()).top(0),
455
344
  left: left
456
345
  });
457
346
  currentColumnWidthPercent += object.getColumnWidthPercent();
@@ -461,7 +350,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
461
350
  });
462
351
  };
463
352
  StackObjectsLayoutFunction.prototype.layoutBody = function (bodyRows, canvas, footerHeight) {
464
- var _a, _b, _c, _d;
465
353
  var canvasDimensions = canvas.getDimensions();
466
354
  var canvasMargin = canvas.getMargin();
467
355
  var workableWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
@@ -474,10 +362,10 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
474
362
  for (var i = 0; i < bodyRows.rows.length; i++) {
475
363
  var row = bodyRows.rows[i];
476
364
  var nextRow = bodyRows.rows[i + 1];
477
- for (var _i = 0, _e = row.objects; _i < _e.length; _i++) {
478
- var object = _e[_i];
365
+ for (var _i = 0, _a = row.objects; _i < _a.length; _i++) {
366
+ var object = _a[_i];
479
367
  var columnOffset = currentColumnWidthPercent / 100 * workableWidth;
480
- var objectMargin = (_a = object.getMargin().left) !== null && _a !== void 0 ? _a : 0;
368
+ var objectMargin = tsOptchain.oc(object.getMargin()).left(0);
481
369
  var objectLeft = canvasMargin.left + columnOffset + objectMargin;
482
370
  if (object.getType() === exports.ObjectType.TEXT && object.isBulleted())
483
371
  objectLeft += object.getBulletMargin();
@@ -486,7 +374,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
486
374
  if (object.getType() === exports.ObjectType.VERTICAL_RULE)
487
375
  return;
488
376
  object.setPosition({
489
- top: nextObjectTop + ((_b = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _b === void 0 ? void 0 : _b.top) || 0,
377
+ top: nextObjectTop + tsOptchain.oc(object.getMargin()).top(0),
490
378
  left: objectLeft
491
379
  });
492
380
  currentColumnWidthPercent += object.getColumnWidthPercent();
@@ -494,17 +382,16 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
494
382
  currentColumnWidthPercent = 0;
495
383
  nextObjectTop += row.height;
496
384
  var thisRowIsHR = row.objects.length === 1 && row.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;
385
+ var nextRowIsHR = tsOptchain.oc(nextRow).objects.length() === 1 && tsOptchain.oc(nextRow).objects()[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
498
386
  if (!thisRowIsHR && !nextRowIsHR) {
499
387
  nextObjectTop += spaceSize;
500
388
  }
501
389
  }
502
390
  };
503
391
  StackObjectsLayoutFunction.prototype.applyWidths = function (objects, layoutWidth) {
504
- ___default["default"](objects).forEach(function (object) {
505
- var _a, _b;
392
+ _(objects).forEach(function (object) {
506
393
  var targetWidth = object.getColumnWidthPercent() / 100 * layoutWidth;
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);
394
+ var actualWidth = targetWidth - tsOptchain.oc(object.getMargin()).left(0) - tsOptchain.oc(object.getMargin()).right(0);
508
395
  if (object.getType() === exports.ObjectType.VERTICAL_RULE)
509
396
  return;
510
397
  if (object.getType() === exports.ObjectType.TEXT && object.isBulleted())
@@ -518,11 +405,10 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
518
405
  });
519
406
  };
520
407
  StackObjectsLayoutFunction.prototype.adjustCanvasSize = function (canvas, requiredHeight) {
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)
408
+ if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
523
409
  return;
524
410
  var dimensions = canvas.getDimensions();
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;
411
+ var minHeight = tsOptchain.oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
526
412
  var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
527
413
  while (targetDimensions.heightPx < requiredHeight) {
528
414
  targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
@@ -555,19 +441,17 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
555
441
  return result;
556
442
  };
557
443
  StackObjectsLayoutFunction.prototype.getObjectHeight = function (element) {
558
- var _a, _b;
559
444
  return element.getBoundingBox().height
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;
445
+ + tsOptchain.oc(element.getMargin()).top(0)
446
+ + tsOptchain.oc(element.getMargin()).bottom(0);
562
447
  };
563
448
  StackObjectsLayoutFunction.prototype.countSpaces = function (rows) {
564
- var _a, _b;
565
449
  var count = 0;
566
450
  for (var i = 0; i < rows.rows.length - 1; i++) {
567
451
  var row = rows.rows[i];
568
452
  var nextRow = rows.rows[i + 1];
569
453
  var thisRowIsHR = row.objects.length === 1 && row.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;
454
+ var nextRowIsHR = tsOptchain.oc(nextRow).objects.length() === 1 && tsOptchain.oc(nextRow).objects()[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
571
455
  if (!thisRowIsHR && !nextRowIsHR) {
572
456
  count++;
573
457
  }
@@ -577,6 +461,26 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
577
461
  return StackObjectsLayoutFunction;
578
462
  }());
579
463
 
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
+
580
484
  var StandardLayoutManager = /** @class */ (function (_super) {
581
485
  __extends(StandardLayoutManager, _super);
582
486
  function StandardLayoutManager(canvas) {
@@ -809,15 +713,14 @@ var AbstractCanvasObject = /** @class */ (function () {
809
713
  * @inheritDoc
810
714
  */
811
715
  AbstractCanvasObject.prototype.setMargin = function (margin) {
812
- var _a, _b;
813
716
  if (!margin)
814
717
  return;
815
- var newMargin = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.margin) !== null && _b !== void 0 ? _b : {
718
+ var newMargin = tsOptchain.oc(this.data).margin({
816
719
  top: 0,
817
720
  right: 0,
818
721
  bottom: 0,
819
722
  left: 0
820
- };
723
+ });
821
724
  if (margin.top != undefined)
822
725
  newMargin.top = margin.top || 0;
823
726
  if (margin.right != undefined)
@@ -834,8 +737,7 @@ var AbstractCanvasObject = /** @class */ (function () {
834
737
  * @inheritDoc
835
738
  */
836
739
  AbstractCanvasObject.prototype.getColumnWidthPercent = function () {
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);
740
+ return Math.max(Math.min(tsOptchain.oc(this.data).columnWidthPercent(100), 100), 0);
839
741
  };
840
742
  /**
841
743
  * @override
@@ -1917,20 +1819,6 @@ var RichText = /** @class */ (function (_super) {
1917
1819
  return RichText;
1918
1820
  }(Image));
1919
1821
 
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
-
1934
1822
  var Text = /** @class */ (function (_super) {
1935
1823
  __extends(Text, _super);
1936
1824
  function Text(canvas, fabricObject, persistedField) {
@@ -2098,7 +1986,7 @@ var Text = /** @class */ (function (_super) {
2098
1986
  Text.prototype.setBoldRegion = function (start, end, bold) {
2099
1987
  if (bold === void 0) { bold = true; }
2100
1988
  if (start > end)
2101
- throw Error("Bad region specified: [".concat(start, " - ").concat(end, "]"));
1989
+ throw Error("Bad region specified: [" + start + " - " + end + "]");
2102
1990
  for (var i = start; i < end; i++) {
2103
1991
  var style = this.fabricObject.getStyleAtPosition(i, true);
2104
1992
  var font = this.fontLibrary.getFont(style.fontFamily);
@@ -2129,7 +2017,7 @@ var Text = /** @class */ (function (_super) {
2129
2017
  Text.prototype.setItalicRegion = function (start, end, italic) {
2130
2018
  if (italic === void 0) { italic = true; }
2131
2019
  if (start > end)
2132
- throw Error("Bad region specified: [".concat(start, " - ").concat(end, "]"));
2020
+ throw Error("Bad region specified: [" + start + " - " + end + "]");
2133
2021
  this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" }, start, end);
2134
2022
  this.redraw();
2135
2023
  };
@@ -2280,7 +2168,7 @@ var Text = /** @class */ (function (_super) {
2280
2168
  if (!this.isBulleted())
2281
2169
  return 0;
2282
2170
  var fontSize = 0;
2283
- ___default["default"].each(this.fabricObject._textLines, function (textLine, lineIndex) {
2171
+ _.each(this.fabricObject._textLines, function (textLine, lineIndex) {
2284
2172
  fontSize = Math.max(fontSize, _this_1.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
2285
2173
  });
2286
2174
  return fontSize * 0.6;
@@ -2293,7 +2181,7 @@ var Text = /** @class */ (function (_super) {
2293
2181
  if (!this.isOrderedList())
2294
2182
  return 0;
2295
2183
  var orderedListMarkerEntities = this.fabricObject._orderedListMarkerEntities;
2296
- var max = ___default["default"](orderedListMarkerEntities)
2184
+ var max = _(orderedListMarkerEntities)
2297
2185
  .filter(function (x) { return !!x; })
2298
2186
  .map(function (x) { return x.getBoundingRect(true, true).width; })
2299
2187
  .max();
@@ -2428,7 +2316,7 @@ var Text = /** @class */ (function (_super) {
2428
2316
  if (this.data.bulleted) {
2429
2317
  var bullets = this.fabricObject["_bullets"];
2430
2318
  delete this.fabricObject["_bullets"];
2431
- ___default["default"].each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2319
+ _.each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2432
2320
  this.fabricObject["objectCaching"] = true;
2433
2321
  }
2434
2322
  };
@@ -2437,7 +2325,7 @@ var Text = /** @class */ (function (_super) {
2437
2325
  if (this.fabricObject._isOrderedList) {
2438
2326
  var markerEntities = this.fabricObject._orderedListMarkerEntities;
2439
2327
  delete this.fabricObject._orderedListMarkerEntities;
2440
- ___default["default"].each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2328
+ _.each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2441
2329
  this.fabricObject["objectCaching"] = true;
2442
2330
  }
2443
2331
  };
@@ -2455,7 +2343,7 @@ var Text = /** @class */ (function (_super) {
2455
2343
  // Determine list of active bullets
2456
2344
  var currentBullets_1 = fabricText["_bullets"];
2457
2345
  var activeBullets_1 = {};
2458
- ___default["default"].each(fabricText._textLines, function (textLine, lineIndex) {
2346
+ _.each(fabricText._textLines, function (textLine, lineIndex) {
2459
2347
  if (textLine.length) {
2460
2348
  // Start of real lines will have offset 0 in styleMap
2461
2349
  var styleMap = fabricText._styleMap[lineIndex];
@@ -2489,13 +2377,13 @@ var Text = /** @class */ (function (_super) {
2489
2377
  var canvas_1 = fabricText.canvas;
2490
2378
  var canvasDirty_1 = false;
2491
2379
  canvas_1.renderOnAddRemove = false;
2492
- ___default["default"].each(activeBullets_1, function (bullet) {
2380
+ _.each(activeBullets_1, function (bullet) {
2493
2381
  if (!canvas_1.contains(bullet)) {
2494
2382
  canvas_1.add(bullet);
2495
2383
  canvasDirty_1 = true;
2496
2384
  }
2497
2385
  });
2498
- ___default["default"].each(currentBullets_1, function (bullet, key) {
2386
+ _.each(currentBullets_1, function (bullet, key) {
2499
2387
  if (!activeBullets_1[key]) {
2500
2388
  canvas_1.remove(bullet);
2501
2389
  canvasDirty_1 = true;
@@ -2511,7 +2399,7 @@ var Text = /** @class */ (function (_super) {
2511
2399
  if (fabricText._isOrderedList) {
2512
2400
  var existingMarkers_1 = fabricText._orderedListMarkerEntities || [];
2513
2401
  var activeMarkers_1 = [];
2514
- ___default["default"].each(fabricText._textLines, function (textLine, lineIndex) {
2402
+ _.each(fabricText._textLines, function (textLine, lineIndex) {
2515
2403
  if (textLine.length) {
2516
2404
  // Start of real lines will have offset 0 in styleMap
2517
2405
  var styleMap = fabricText._styleMap[lineIndex];
@@ -2522,7 +2410,7 @@ var Text = /** @class */ (function (_super) {
2522
2410
  }
2523
2411
  else {
2524
2412
  // Create new marker for this line
2525
- var textbox = new fabric.Textbox("".concat(lineIndex, "."), {
2413
+ var textbox = new fabric.Textbox(lineIndex + ".", {
2526
2414
  left: 0,
2527
2415
  top: 0,
2528
2416
  fill: fabricText.fill,
@@ -2544,7 +2432,7 @@ var Text = /** @class */ (function (_super) {
2544
2432
  var canvas_2 = fabricText.canvas;
2545
2433
  var canvasDirty_2 = false;
2546
2434
  canvas_2.renderOnAddRemove = false;
2547
- ___default["default"].each(activeMarkers_1, function (marker) {
2435
+ _.each(activeMarkers_1, function (marker) {
2548
2436
  if (!marker)
2549
2437
  return;
2550
2438
  if (!canvas_2.contains(marker)) {
@@ -2552,7 +2440,7 @@ var Text = /** @class */ (function (_super) {
2552
2440
  canvasDirty_2 = true;
2553
2441
  }
2554
2442
  });
2555
- ___default["default"].each(existingMarkers_1, function (marker, key) {
2443
+ _.each(existingMarkers_1, function (marker, key) {
2556
2444
  if (!marker)
2557
2445
  return;
2558
2446
  if (!activeMarkers_1[key]) {
@@ -2621,7 +2509,7 @@ var Text = /** @class */ (function (_super) {
2621
2509
  left: fabricText.left + xOffset,
2622
2510
  top: fabricText.top + yOffset,
2623
2511
  angle: fabricText.angle,
2624
- text: "".concat(lineNumber, ".")
2512
+ text: lineNumber + "."
2625
2513
  });
2626
2514
  }
2627
2515
  originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
@@ -2832,7 +2720,6 @@ var DefaultCanvasProfile = /** @class */ (function () {
2832
2720
  return DefaultCanvasProfile;
2833
2721
  }());
2834
2722
 
2835
- exports.ImageType = void 0;
2836
2723
  (function (ImageType) {
2837
2724
  ImageType["DEFAULT"] = "DEFAULT";
2838
2725
  ImageType["BACKGROUND"] = "BACKGROUND";
@@ -2840,6 +2727,19 @@ exports.ImageType = void 0;
2840
2727
  ImageType["PHOTO"] = "PHOTO";
2841
2728
  })(exports.ImageType || (exports.ImageType = {}));
2842
2729
 
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
+
2843
2743
  var AbstractInteractiveCanvas = /** @class */ (function () {
2844
2744
  function AbstractInteractiveCanvas(fabric, fabricCanvas, devicePixelRatio) {
2845
2745
  this.fabric = fabric;
@@ -3021,12 +2921,11 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3021
2921
  * @inheritDoc
3022
2922
  */
3023
2923
  AbstractInteractiveCanvas.prototype.setDimensionRestrictions = function (restrictions) {
3024
- var _a, _b, _c, _d, _e, _f, _g, _h;
3025
2924
  this.dimensionRestrictions$.next(restrictions);
3026
2925
  var dimensions = this.getDimensions();
3027
2926
  if (this.dimensionsExceedRestrictions(dimensions)) {
3028
2927
  var newDimensions = dimensions
3029
- .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(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))));
3030
2929
  this.setBaseDimensions(newDimensions);
3031
2930
  }
3032
2931
  };
@@ -3095,7 +2994,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3095
2994
  * @inheritDoc
3096
2995
  */
3097
2996
  AbstractInteractiveCanvas.prototype.getObjectsByTypeInternal = function (type) {
3098
- return ___default["default"](this.getObjectsInternal())
2997
+ return _(this.getObjectsInternal())
3099
2998
  .filter(function (object) { return object.getType() === type; })
3100
2999
  .value();
3101
3000
  };
@@ -3108,8 +3007,8 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3108
3007
  for (var _i = 0; _i < arguments.length; _i++) {
3109
3008
  types[_i] = arguments[_i];
3110
3009
  }
3111
- return ___default["default"](this.getObjectsInternal())
3112
- .filter(function (object) { return ___default["default"](types).includes(object.getType()); })
3010
+ return _(this.getObjectsInternal())
3011
+ .filter(function (object) { return _(types).includes(object.getType()); })
3113
3012
  .value();
3114
3013
  };
3115
3014
  /**
@@ -3126,7 +3025,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3126
3025
  AbstractInteractiveCanvas.prototype.removeObject = function (target) {
3127
3026
  var concreteObject = this.findFabricObject(target.getId());
3128
3027
  this.fabricCanvas.remove(concreteObject);
3129
- this.objects$.next(___default["default"](this.objects$.value)
3028
+ this.objects$.next(_(this.objects$.value)
3130
3029
  .filter(function (object) { return object.getId() !== target.getId(); })
3131
3030
  .value());
3132
3031
  this.onObjectListChange();
@@ -3426,7 +3325,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3426
3325
  * @inheritDoc
3427
3326
  */
3428
3327
  AbstractInteractiveCanvas.prototype.setPrefillData = function (data) {
3429
- ___default["default"](this.getObjectsByTypeInternal(exports.ObjectType.TEXT)).each(function (object) {
3328
+ _(this.getObjectsByTypeInternal(exports.ObjectType.TEXT)).each(function (object) {
3430
3329
  var prefillType = object.getPrefillType();
3431
3330
  if (prefillType !== undefined) {
3432
3331
  object.setText(data[prefillType] || "");
@@ -3440,10 +3339,10 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3440
3339
  AbstractInteractiveCanvas.prototype.distributeObjectsVertically = function () {
3441
3340
  var margin = this.getMargin();
3442
3341
  var canvasHeight = this.getDimensions().heightPx;
3443
- var objectsToLayout = ___default["default"](this.getObjectsByTypesInternal(exports.ObjectType.TEXT, exports.ObjectType.IMAGE))
3342
+ var objectsToLayout = _(this.getObjectsByTypesInternal(exports.ObjectType.TEXT, exports.ObjectType.IMAGE))
3444
3343
  .sortBy(function (x) { return x.getBoundingBox().top; })
3445
3344
  .value();
3446
- var objectsHeight = ___default["default"].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);
3447
3346
  var workableHeight = canvasHeight - margin.top - margin.bottom;
3448
3347
  var requiredPadding = workableHeight - objectsHeight;
3449
3348
  var spaceBetween = requiredPadding / (objectsToLayout.length - 1);
@@ -3512,7 +3411,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3512
3411
  * @inheritDoc
3513
3412
  */
3514
3413
  AbstractInteractiveCanvas.prototype.save = function () {
3515
- var objects = ___default["default"](this.objects$.value)
3414
+ var objects = _(this.objects$.value)
3516
3415
  .map(function (x) { return x.persist(); })
3517
3416
  .value();
3518
3417
  var includedProperties = ["id", "_isSlaveObject", "_isOrderedList", "_orderedListStart"];
@@ -3617,7 +3516,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3617
3516
  if (activeObject) {
3618
3517
  this.fabricCanvas.setActiveObject(activeObject);
3619
3518
  }
3620
- return ___default["default"].replace(base64, /^data:.*;base64,/, "");
3519
+ return _.replace(base64, /^data:.*;base64,/, "");
3621
3520
  };
3622
3521
  /**
3623
3522
  * @override
@@ -3655,7 +3554,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3655
3554
  };
3656
3555
  AbstractInteractiveCanvas.prototype.syncObjectList = function () {
3657
3556
  var _this = this;
3658
- var newObjectList = ___default["default"](this.fabricCanvas.getObjects())
3557
+ var newObjectList = _(this.fabricCanvas.getObjects())
3659
3558
  .map(function (obj) { return _this.findObject(obj.id); })
3660
3559
  .filter(function (x) { return x !== undefined; })
3661
3560
  .value();
@@ -3703,7 +3602,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3703
3602
  };
3704
3603
  AbstractInteractiveCanvas.prototype.bindFields = function (persistedFields) {
3705
3604
  var _this = this;
3706
- var bound = ___default["default"](persistedFields)
3605
+ var bound = _(persistedFields)
3707
3606
  .flatMap(function (field) {
3708
3607
  try {
3709
3608
  return [_this.bindField(field)];
@@ -3739,20 +3638,20 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3739
3638
  case exports.ObjectType.BACKGROUND_IMAGE:
3740
3639
  return new BackgroundImage(this, fabricObject, persistedField);
3741
3640
  default:
3742
- throw new Error("Unknown field type: [".concat(persistedField.type, "]"));
3641
+ throw new Error("Unknown field type: [" + persistedField.type + "]");
3743
3642
  }
3744
3643
  };
3745
3644
  AbstractInteractiveCanvas.prototype.findFabricObject = function (id) {
3746
3645
  var objects = this.fabricCanvas.getObjects();
3747
- var fabricObject = ___default["default"].find(objects, function (o) { return o.id == id; });
3646
+ var fabricObject = _.find(objects, function (o) { return o.id == id; });
3748
3647
  if (!fabricObject) {
3749
- throw new Error("Cannot find fabric object with id [".concat(id, "]"));
3648
+ throw new Error("Cannot find fabric object with id [" + id + "]");
3750
3649
  }
3751
3650
  return fabricObject;
3752
3651
  };
3753
3652
  AbstractInteractiveCanvas.prototype.findObject = function (id) {
3754
3653
  //Don't use strict compare here. fabric ids are numbers while ad builder ids are strings... mostly.
3755
- return ___default["default"].find(this.objects$.value, function (object) { return object.getId() == id; });
3654
+ return _.find(this.objects$.value, function (object) { return object.getId() == id; });
3756
3655
  };
3757
3656
  /**
3758
3657
  * Reset zoom and canvas dimensions to 1:1 scale, execute a function, then return the canvas to
@@ -3790,11 +3689,11 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3790
3689
  if (!object) {
3791
3690
  return null;
3792
3691
  }
3793
- return ___default["default"].find(this.objects$.value, function (field) { return field.getId() == object.id; });
3692
+ return _.find(this.objects$.value, function (field) { return field.getId() == object.id; });
3794
3693
  };
3795
3694
  AbstractInteractiveCanvas.prototype.getFieldsByCanvasObject = function (objects) {
3796
3695
  var _this = this;
3797
- return ___default["default"](objects)
3696
+ return _(objects)
3798
3697
  .map(function (obj) { return _this.getFieldByCanvasObject(obj); })
3799
3698
  .reject(function (x) { return !x; })
3800
3699
  .value();
@@ -3802,7 +3701,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3802
3701
  AbstractInteractiveCanvas.prototype.calculateImageCaptureCoefficient = function () {
3803
3702
  var precision = 3;
3804
3703
  var devicePixelRatio = this.devicePixelRatio || 1;
3805
- return ___default["default"].round(2 / devicePixelRatio, precision);
3704
+ return _.round(2 / devicePixelRatio, precision);
3806
3705
  };
3807
3706
  AbstractInteractiveCanvas.prototype.randomId = function () {
3808
3707
  var min = 0;
@@ -3811,23 +3710,22 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3811
3710
  return (new Date()).getTime() + "" + id;
3812
3711
  };
3813
3712
  AbstractInteractiveCanvas.prototype.getLowestTextPoint = function () {
3814
- return ___default["default"](this.objects$.value)
3713
+ return _(this.objects$.value)
3815
3714
  .filter(function (object) { return object.getType() === exports.ObjectType.TEXT; })
3816
3715
  .map(function (text) { return text.getDimensions().top.px + text.getDimensions().height.px; })
3817
3716
  .reduce(function (x, y) { return Math.max(x, y); }, 0);
3818
3717
  };
3819
3718
  AbstractInteractiveCanvas.prototype.trackNewObject = function (object) {
3820
- this.objects$.next(__spreadArray(__spreadArray([], this.objects$.value, true), [object], false));
3719
+ this.objects$.next(__spreadArrays(this.objects$.value, [object]));
3821
3720
  };
3822
3721
  AbstractInteractiveCanvas.prototype.dimensionsExceedRestrictions = function (dimensions) {
3823
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
3824
3722
  var restrictions = this.dimensionRestrictions$.value;
3825
- 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)
3826
- || ((_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)
3827
- || ((_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)
3828
- || ((_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)
3829
- || ((_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)
3830
- || ((_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 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();
3831
3729
  };
3832
3730
  return AbstractInteractiveCanvas;
3833
3731
  }());
@@ -3839,11 +3737,7 @@ var SelectionData = /** @class */ (function () {
3839
3737
  this.isText = selectedObject
3840
3738
  && selectedObject.getType() === exports.ObjectType.TEXT
3841
3739
  && selectedObject.isEditing();
3842
- this.event = {};
3843
3740
  }
3844
- SelectionData.prototype.setEvent = function (event) {
3845
- this.event = event;
3846
- };
3847
3741
  return SelectionData;
3848
3742
  }());
3849
3743
 
@@ -3955,9 +3849,9 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3955
3849
  _this.headless = false;
3956
3850
  _this.undoStack = new UndoStack(_this);
3957
3851
  //Initialize watchers
3958
- _this.fabricCanvas.on("selection:updated", function (event) { return _this.onFabricSelectionChanged(event); });
3959
- _this.fabricCanvas.on("selection:created", function (event) { return _this.onFabricSelectionChanged(event); });
3960
- _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(); });
3961
3855
  _this.fabricCanvas.on("text:editing:entered", function () { return _this.onTextEditing(); });
3962
3856
  _this.fabricCanvas.on("text:editing:exited", function () { return _this.onTextEditing(); });
3963
3857
  _this.fabricCanvas.on("text:changed", function () { return _this.onTextChange(); });
@@ -4002,11 +3896,9 @@ var InteractiveCanvas = /** @class */ (function (_super) {
4002
3896
  });
4003
3897
  });
4004
3898
  };
4005
- InteractiveCanvas.prototype.onFabricSelectionChanged = function (event) {
3899
+ InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
4006
3900
  var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
4007
- var selection = new SelectionData(selected);
4008
- selection.setEvent(event);
4009
- this.selection$.next(selection);
3901
+ this.selection$.next(new SelectionData(selected));
4010
3902
  this.enterTextSelectionModeIfRequired();
4011
3903
  };
4012
3904
  InteractiveCanvas.prototype.enterTextSelectionModeIfRequired = function () {
@@ -4024,6 +3916,82 @@ var InteractiveCanvas = /** @class */ (function (_super) {
4024
3916
  return InteractiveCanvas;
4025
3917
  }(AbstractInteractiveCanvas));
4026
3918
 
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
+
4027
3995
  exports.AbstractCanvasObject = AbstractCanvasObject;
4028
3996
  exports.AbstractInteractiveCanvas = AbstractInteractiveCanvas;
4029
3997
  exports.AbstractLayoutManager = AbstractLayoutManager;