@leapfrog/interactive-canvas 2.0.17-beta-1 → 2.0.18-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.
@@ -1,29 +1,27 @@
1
- import * as _ from 'lodash';
2
- import { round, each, values, reduce, clone, replace, find, isEqual } from 'lodash';
3
- import { oc } from 'ts-optchain';
1
+ import _, { round, each, values, reduce, clone, isEqual } from 'lodash';
4
2
  import { BehaviorSubject, Subject } from 'rxjs';
5
3
  import { fabric } from 'fabric';
6
4
 
7
- var PIXELS_PER_MM = 3.937;
5
+ var PIXELS_PER_MM$2 = 3.937;
8
6
  var MillimeterDimensions = /** @class */ (function () {
9
7
  function MillimeterDimensions(width, height) {
10
8
  this.widthUnit = "mm";
11
9
  this.heightUnit = "mm";
12
10
  this.width = width;
13
11
  this.widthMm = Math.max(0, width);
14
- this.widthPx = round(this.widthMm * PIXELS_PER_MM);
12
+ this.widthPx = round(this.widthMm * PIXELS_PER_MM$2);
15
13
  this.height = height;
16
14
  this.heightMm = Math.max(0, height);
17
- this.heightPx = round(this.heightMm * PIXELS_PER_MM);
15
+ this.heightPx = round(this.heightMm * PIXELS_PER_MM$2);
18
16
  }
19
17
  MillimeterDimensions.prototype.withSize = function (width, height) {
20
18
  return new MillimeterDimensions(width, height);
21
19
  };
22
20
  MillimeterDimensions.prototype.widthPxToMm = function (px) {
23
- return px / PIXELS_PER_MM;
21
+ return px / PIXELS_PER_MM$2;
24
22
  };
25
23
  MillimeterDimensions.prototype.heightPxToMm = function (px) {
26
- return px / PIXELS_PER_MM;
24
+ return px / PIXELS_PER_MM$2;
27
25
  };
28
26
  return MillimeterDimensions;
29
27
  }());
@@ -49,8 +47,8 @@ var PixelCanvasDimensions = /** @class */ (function () {
49
47
  return PixelCanvasDimensions;
50
48
  }());
51
49
 
52
- var COLUMN_WIDTH_MM = 41;
53
- var GUTTER_WIDTH_MM = 3;
50
+ var COLUMN_WIDTH_MM$1 = 41;
51
+ var GUTTER_WIDTH_MM$1 = 3;
54
52
  var PIXELS_PER_MM$1 = 3.937;
55
53
  var Print6ColCanvasDimensions = /** @class */ (function () {
56
54
  function Print6ColCanvasDimensions(width, height) {
@@ -58,8 +56,8 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
58
56
  this.heightUnit = "cm";
59
57
  this.width = width;
60
58
  this.gutterCount = Math.max(0, width - 1);
61
- this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
62
- this.columnsTotalMm = width * COLUMN_WIDTH_MM;
59
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
60
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
63
61
  this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
64
62
  this.widthPx = round(this.widthMm * PIXELS_PER_MM$1);
65
63
  this.height = height;
@@ -78,110 +76,119 @@ var Print6ColCanvasDimensions = /** @class */ (function () {
78
76
  return Print6ColCanvasDimensions;
79
77
  }());
80
78
 
81
- var COLUMN_WIDTH_MM$1 = 30.8772;
82
- var GUTTER_WIDTH_MM$1 = 2.1053;
83
- var PIXELS_PER_MM$2 = 3.937;
79
+ var COLUMN_WIDTH_MM = 30.8772;
80
+ var GUTTER_WIDTH_MM = 2.1053;
81
+ var PIXELS_PER_MM = 3.937;
84
82
  var Print8ColCanvasDimensions = /** @class */ (function () {
85
83
  function Print8ColCanvasDimensions(width, height) {
86
84
  this.widthUnit = "column(s)";
87
85
  this.heightUnit = "cm";
88
86
  this.width = width;
89
87
  this.gutterCount = Math.max(0, width - 1);
90
- this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
91
- this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
88
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
89
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM;
92
90
  this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
93
- this.widthPx = round(this.widthMm * PIXELS_PER_MM$2);
91
+ this.widthPx = round(this.widthMm * PIXELS_PER_MM);
94
92
  this.height = height;
95
93
  this.heightMm = Math.max(0, height * 10);
96
- this.heightPx = round(this.heightMm * PIXELS_PER_MM$2);
94
+ this.heightPx = round(this.heightMm * PIXELS_PER_MM);
97
95
  }
98
96
  Print8ColCanvasDimensions.prototype.withSize = function (width, height) {
99
97
  return new Print8ColCanvasDimensions(width, height);
100
98
  };
101
99
  Print8ColCanvasDimensions.prototype.widthPxToMm = function (px) {
102
- return px / PIXELS_PER_MM$2;
100
+ return px / PIXELS_PER_MM;
103
101
  };
104
102
  Print8ColCanvasDimensions.prototype.heightPxToMm = function (px) {
105
- return px / PIXELS_PER_MM$2;
103
+ return px / PIXELS_PER_MM;
106
104
  };
107
105
  return Print8ColCanvasDimensions;
108
106
  }());
109
107
 
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);
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;
131
190
  };
132
191
 
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
-
185
192
  var Font = /** @class */ (function () {
186
193
  function Font() {
187
194
  }
@@ -284,6 +291,64 @@ var RedrawAllLayoutFunction = /** @class */ (function () {
284
291
  return RedrawAllLayoutFunction;
285
292
  }());
286
293
 
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
+
287
352
  var LayoutManager;
288
353
  (function (LayoutManager) {
289
354
  LayoutManager["LEGACY"] = "LEGACY";
@@ -291,6 +356,45 @@ var LayoutManager;
291
356
  LayoutManager["ADVANCED"] = "ADVANCED";
292
357
  })(LayoutManager || (LayoutManager = {}));
293
358
 
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
+
294
398
  var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
295
399
  function UpdateObjectDimensionsLayoutFunction() {
296
400
  }
@@ -332,13 +436,14 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
332
436
  var currentColumnWidthPercent = 0;
333
437
  each(footerRows.rows, function (row) {
334
438
  each(row.objects, function (object) {
439
+ var _a, _b, _c;
335
440
  var columnOffset = currentColumnWidthPercent / 100 * layoutAreaWidth;
336
- var objectMargin = oc(object.getMargin()).left(0);
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;
337
442
  var left = canvasMargin.left + columnOffset + objectMargin;
338
443
  if (object.getType() === ObjectType.VERTICAL_RULE)
339
444
  object.setPosition({ height: row.height });
340
445
  object.setPosition({
341
- top: nextObjectTop + oc(object.getMargin()).top(0),
446
+ top: nextObjectTop + ((_c = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _c === void 0 ? void 0 : _c.top) || 0,
342
447
  left: left
343
448
  });
344
449
  currentColumnWidthPercent += object.getColumnWidthPercent();
@@ -348,6 +453,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
348
453
  });
349
454
  };
350
455
  StackObjectsLayoutFunction.prototype.layoutBody = function (bodyRows, canvas, footerHeight) {
456
+ var _a, _b, _c, _d;
351
457
  var canvasDimensions = canvas.getDimensions();
352
458
  var canvasMargin = canvas.getMargin();
353
459
  var workableWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
@@ -360,10 +466,10 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
360
466
  for (var i = 0; i < bodyRows.rows.length; i++) {
361
467
  var row = bodyRows.rows[i];
362
468
  var nextRow = bodyRows.rows[i + 1];
363
- for (var _i = 0, _a = row.objects; _i < _a.length; _i++) {
364
- var object = _a[_i];
469
+ for (var _i = 0, _e = row.objects; _i < _e.length; _i++) {
470
+ var object = _e[_i];
365
471
  var columnOffset = currentColumnWidthPercent / 100 * workableWidth;
366
- var objectMargin = oc(object.getMargin()).left(0);
472
+ var objectMargin = (_a = object.getMargin().left) !== null && _a !== void 0 ? _a : 0;
367
473
  var objectLeft = canvasMargin.left + columnOffset + objectMargin;
368
474
  if (object.getType() === ObjectType.TEXT && object.isBulleted())
369
475
  objectLeft += object.getBulletMargin();
@@ -372,7 +478,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
372
478
  if (object.getType() === ObjectType.VERTICAL_RULE)
373
479
  return;
374
480
  object.setPosition({
375
- top: nextObjectTop + oc(object.getMargin()).top(0),
481
+ top: nextObjectTop + ((_b = object === null || object === void 0 ? void 0 : object.getMargin()) === null || _b === void 0 ? void 0 : _b.top) || 0,
376
482
  left: objectLeft
377
483
  });
378
484
  currentColumnWidthPercent += object.getColumnWidthPercent();
@@ -380,7 +486,7 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
380
486
  currentColumnWidthPercent = 0;
381
487
  nextObjectTop += row.height;
382
488
  var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === ObjectType.HORIZONTAL_RULE;
383
- var nextRowIsHR = oc(nextRow).objects.length() === 1 && oc(nextRow).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;
384
490
  if (!thisRowIsHR && !nextRowIsHR) {
385
491
  nextObjectTop += spaceSize;
386
492
  }
@@ -388,8 +494,9 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
388
494
  };
389
495
  StackObjectsLayoutFunction.prototype.applyWidths = function (objects, layoutWidth) {
390
496
  _(objects).forEach(function (object) {
497
+ var _a, _b;
391
498
  var targetWidth = object.getColumnWidthPercent() / 100 * layoutWidth;
392
- var actualWidth = targetWidth - oc(object.getMargin()).left(0) - oc(object.getMargin()).right(0);
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);
393
500
  if (object.getType() === ObjectType.VERTICAL_RULE)
394
501
  return;
395
502
  if (object.getType() === ObjectType.TEXT && object.isBulleted())
@@ -403,10 +510,11 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
403
510
  });
404
511
  };
405
512
  StackObjectsLayoutFunction.prototype.adjustCanvasSize = function (canvas, requiredHeight) {
406
- if (oc(canvas.getDimensionsRestrictions()).fixed(false))
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)
407
515
  return;
408
516
  var dimensions = canvas.getDimensions();
409
- var minHeight = oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
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;
410
518
  var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
411
519
  while (targetDimensions.heightPx < requiredHeight) {
412
520
  targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
@@ -439,17 +547,19 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
439
547
  return result;
440
548
  };
441
549
  StackObjectsLayoutFunction.prototype.getObjectHeight = function (element) {
550
+ var _a, _b;
442
551
  return element.getBoundingBox().height
443
- + oc(element.getMargin()).top(0)
444
- + oc(element.getMargin()).bottom(0);
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);
445
554
  };
446
555
  StackObjectsLayoutFunction.prototype.countSpaces = function (rows) {
556
+ var _a, _b;
447
557
  var count = 0;
448
558
  for (var i = 0; i < rows.rows.length - 1; i++) {
449
559
  var row = rows.rows[i];
450
560
  var nextRow = rows.rows[i + 1];
451
561
  var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === ObjectType.HORIZONTAL_RULE;
452
- var nextRowIsHR = oc(nextRow).objects.length() === 1 && oc(nextRow).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;
453
563
  if (!thisRowIsHR && !nextRowIsHR) {
454
564
  count++;
455
565
  }
@@ -459,26 +569,6 @@ var StackObjectsLayoutFunction = /** @class */ (function () {
459
569
  return StackObjectsLayoutFunction;
460
570
  }());
461
571
 
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
-
482
572
  var StandardLayoutManager = /** @class */ (function (_super) {
483
573
  __extends(StandardLayoutManager, _super);
484
574
  function StandardLayoutManager(canvas) {
@@ -711,14 +801,15 @@ var AbstractCanvasObject = /** @class */ (function () {
711
801
  * @inheritDoc
712
802
  */
713
803
  AbstractCanvasObject.prototype.setMargin = function (margin) {
804
+ var _a, _b;
714
805
  if (!margin)
715
806
  return;
716
- var newMargin = oc(this.data).margin({
807
+ var newMargin = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.margin) !== null && _b !== void 0 ? _b : {
717
808
  top: 0,
718
809
  right: 0,
719
810
  bottom: 0,
720
811
  left: 0
721
- });
812
+ };
722
813
  if (margin.top != undefined)
723
814
  newMargin.top = margin.top || 0;
724
815
  if (margin.right != undefined)
@@ -735,7 +826,8 @@ var AbstractCanvasObject = /** @class */ (function () {
735
826
  * @inheritDoc
736
827
  */
737
828
  AbstractCanvasObject.prototype.getColumnWidthPercent = function () {
738
- return Math.max(Math.min(oc(this.data).columnWidthPercent(100), 100), 0);
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);
739
831
  };
740
832
  /**
741
833
  * @override
@@ -1817,6 +1909,20 @@ var RichText = /** @class */ (function (_super) {
1817
1909
  return RichText;
1818
1910
  }(Image));
1819
1911
 
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
+
1820
1926
  var Text = /** @class */ (function (_super) {
1821
1927
  __extends(Text, _super);
1822
1928
  function Text(canvas, fabricObject, persistedField) {
@@ -1870,6 +1976,21 @@ var Text = /** @class */ (function (_super) {
1870
1976
  this.data.userText = this.fabricObject.text;
1871
1977
  this.text$.next(this.fabricObject.text);
1872
1978
  };
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
+ };
1873
1994
  /**
1874
1995
  * @override
1875
1996
  * @inheritDoc
@@ -1984,7 +2105,7 @@ var Text = /** @class */ (function (_super) {
1984
2105
  Text.prototype.setBoldRegion = function (start, end, bold) {
1985
2106
  if (bold === void 0) { bold = true; }
1986
2107
  if (start > end)
1987
- throw Error("Bad region specified: [" + start + " - " + end + "]");
2108
+ throw Error("Bad region specified: [".concat(start, " - ").concat(end, "]"));
1988
2109
  for (var i = start; i < end; i++) {
1989
2110
  var style = this.fabricObject.getStyleAtPosition(i, true);
1990
2111
  var font = this.fontLibrary.getFont(style.fontFamily);
@@ -2015,7 +2136,7 @@ var Text = /** @class */ (function (_super) {
2015
2136
  Text.prototype.setItalicRegion = function (start, end, italic) {
2016
2137
  if (italic === void 0) { italic = true; }
2017
2138
  if (start > end)
2018
- throw Error("Bad region specified: [" + start + " - " + end + "]");
2139
+ throw Error("Bad region specified: [".concat(start, " - ").concat(end, "]"));
2019
2140
  this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" }, start, end);
2020
2141
  this.redraw();
2021
2142
  };
@@ -2166,7 +2287,7 @@ var Text = /** @class */ (function (_super) {
2166
2287
  if (!this.isBulleted())
2167
2288
  return 0;
2168
2289
  var fontSize = 0;
2169
- each(this.fabricObject._textLines, function (textLine, lineIndex) {
2290
+ _.each(this.fabricObject._textLines, function (textLine, lineIndex) {
2170
2291
  fontSize = Math.max(fontSize, _this_1.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
2171
2292
  });
2172
2293
  return fontSize * 0.6;
@@ -2245,9 +2366,10 @@ var Text = /** @class */ (function (_super) {
2245
2366
  * @inheritDoc
2246
2367
  */
2247
2368
  Text.prototype.enableBullets = function () {
2369
+ var _a;
2248
2370
  this.disableOrderedList();
2249
2371
  this.fabricObject["objectCaching"] = false;
2250
- this.fabricObject["_bullets"] = this.fabricObject["_bullets"] || {};
2372
+ this.fabricObject["_bullets"] = (_a = this.fabricObject["_bullets"]) !== null && _a !== void 0 ? _a : {};
2251
2373
  this.data.bulleted = true;
2252
2374
  this.notifyCanvasOfTextChanges();
2253
2375
  this.redraw();
@@ -2314,7 +2436,7 @@ var Text = /** @class */ (function (_super) {
2314
2436
  if (this.data.bulleted) {
2315
2437
  var bullets = this.fabricObject["_bullets"];
2316
2438
  delete this.fabricObject["_bullets"];
2317
- each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2439
+ _.each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2318
2440
  this.fabricObject["objectCaching"] = true;
2319
2441
  }
2320
2442
  };
@@ -2323,7 +2445,7 @@ var Text = /** @class */ (function (_super) {
2323
2445
  if (this.fabricObject._isOrderedList) {
2324
2446
  var markerEntities = this.fabricObject._orderedListMarkerEntities;
2325
2447
  delete this.fabricObject._orderedListMarkerEntities;
2326
- each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2448
+ _.each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2327
2449
  this.fabricObject["objectCaching"] = true;
2328
2450
  }
2329
2451
  };
@@ -2336,12 +2458,13 @@ var Text = /** @class */ (function (_super) {
2336
2458
  var originalRender = this.fabricObject["_render"];
2337
2459
  var fabric = this.canvas.fabric;
2338
2460
  this.fabricObject["_render"] = function (ctx) {
2461
+ var _a;
2339
2462
  var fabricText = this;
2340
2463
  if (fabricText["_bullets"]) {
2341
2464
  // Determine list of active bullets
2342
2465
  var currentBullets_1 = fabricText["_bullets"];
2343
2466
  var activeBullets_1 = {};
2344
- each(fabricText._textLines, function (textLine, lineIndex) {
2467
+ _.each(fabricText._textLines, function (textLine, lineIndex) {
2345
2468
  if (textLine.length) {
2346
2469
  // Start of real lines will have offset 0 in styleMap
2347
2470
  var styleMap = fabricText._styleMap[lineIndex];
@@ -2375,13 +2498,13 @@ var Text = /** @class */ (function (_super) {
2375
2498
  var canvas_1 = fabricText.canvas;
2376
2499
  var canvasDirty_1 = false;
2377
2500
  canvas_1.renderOnAddRemove = false;
2378
- each(activeBullets_1, function (bullet) {
2501
+ _.each(activeBullets_1, function (bullet) {
2379
2502
  if (!canvas_1.contains(bullet)) {
2380
2503
  canvas_1.add(bullet);
2381
2504
  canvasDirty_1 = true;
2382
2505
  }
2383
2506
  });
2384
- each(currentBullets_1, function (bullet, key) {
2507
+ _.each(currentBullets_1, function (bullet, key) {
2385
2508
  if (!activeBullets_1[key]) {
2386
2509
  canvas_1.remove(bullet);
2387
2510
  canvasDirty_1 = true;
@@ -2395,9 +2518,9 @@ var Text = /** @class */ (function (_super) {
2395
2518
  }
2396
2519
  }
2397
2520
  if (fabricText._isOrderedList) {
2398
- var existingMarkers_1 = fabricText._orderedListMarkerEntities || [];
2521
+ var existingMarkers_1 = (_a = fabricText._orderedListMarkerEntities) !== null && _a !== void 0 ? _a : [];
2399
2522
  var activeMarkers_1 = [];
2400
- each(fabricText._textLines, function (textLine, lineIndex) {
2523
+ _.each(fabricText._textLines, function (textLine, lineIndex) {
2401
2524
  if (textLine.length) {
2402
2525
  // Start of real lines will have offset 0 in styleMap
2403
2526
  var styleMap = fabricText._styleMap[lineIndex];
@@ -2408,7 +2531,7 @@ var Text = /** @class */ (function (_super) {
2408
2531
  }
2409
2532
  else {
2410
2533
  // Create new marker for this line
2411
- var textbox = new fabric.Textbox(lineIndex + ".", {
2534
+ var textbox = new fabric.Textbox("".concat(lineIndex, "."), {
2412
2535
  left: 0,
2413
2536
  top: 0,
2414
2537
  fill: fabricText.fill,
@@ -2430,7 +2553,7 @@ var Text = /** @class */ (function (_super) {
2430
2553
  var canvas_2 = fabricText.canvas;
2431
2554
  var canvasDirty_2 = false;
2432
2555
  canvas_2.renderOnAddRemove = false;
2433
- each(activeMarkers_1, function (marker) {
2556
+ _.each(activeMarkers_1, function (marker) {
2434
2557
  if (!marker)
2435
2558
  return;
2436
2559
  if (!canvas_2.contains(marker)) {
@@ -2438,7 +2561,7 @@ var Text = /** @class */ (function (_super) {
2438
2561
  canvasDirty_2 = true;
2439
2562
  }
2440
2563
  });
2441
- each(existingMarkers_1, function (marker, key) {
2564
+ _.each(existingMarkers_1, function (marker, key) {
2442
2565
  if (!marker)
2443
2566
  return;
2444
2567
  if (!activeMarkers_1[key]) {
@@ -2507,7 +2630,7 @@ var Text = /** @class */ (function (_super) {
2507
2630
  left: fabricText.left + xOffset,
2508
2631
  top: fabricText.top + yOffset,
2509
2632
  angle: fabricText.angle,
2510
- text: lineNumber + "."
2633
+ text: "".concat(lineNumber, ".")
2511
2634
  });
2512
2635
  }
2513
2636
  originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
@@ -2564,6 +2687,7 @@ var Text = /** @class */ (function (_super) {
2564
2687
  Text.prototype.notifyCanvasOfTextChanges = function () {
2565
2688
  this.canvas.notifyTextChanged();
2566
2689
  };
2690
+ Text.NEW_LINE = "\n";
2567
2691
  return Text;
2568
2692
  }(AbstractCanvasObject));
2569
2693
  var TextSelection = /** @class */ (function () {
@@ -2726,20 +2850,6 @@ var ImageType;
2726
2850
  ImageType["PHOTO"] = "PHOTO";
2727
2851
  })(ImageType || (ImageType = {}));
2728
2852
 
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
-
2743
2853
  var AbstractInteractiveCanvas = /** @class */ (function () {
2744
2854
  function AbstractInteractiveCanvas(fabric, fabricCanvas, devicePixelRatio) {
2745
2855
  this.fabric = fabric;
@@ -2921,11 +3031,12 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
2921
3031
  * @inheritDoc
2922
3032
  */
2923
3033
  AbstractInteractiveCanvas.prototype.setDimensionRestrictions = function (restrictions) {
3034
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2924
3035
  this.dimensionRestrictions$.next(restrictions);
2925
3036
  var dimensions = this.getDimensions();
2926
3037
  if (this.dimensionsExceedRestrictions(dimensions)) {
2927
3038
  var newDimensions = dimensions
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))));
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)));
2929
3040
  this.setBaseDimensions(newDimensions);
2930
3041
  }
2931
3042
  };
@@ -3342,7 +3453,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3342
3453
  var objectsToLayout = _(this.getObjectsByTypesInternal(ObjectType.TEXT, ObjectType.IMAGE))
3343
3454
  .sortBy(function (x) { return x.getBoundingBox().top; })
3344
3455
  .value();
3345
- var objectsHeight = reduce(objectsToLayout, function (total, element) { return total + element.getBoundingBox().height; }, 0);
3456
+ var objectsHeight = _.reduce(objectsToLayout, function (total, element) { return total + element.getBoundingBox().height; }, 0);
3346
3457
  var workableHeight = canvasHeight - margin.top - margin.bottom;
3347
3458
  var requiredPadding = workableHeight - objectsHeight;
3348
3459
  var spaceBetween = requiredPadding / (objectsToLayout.length - 1);
@@ -3516,7 +3627,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3516
3627
  if (activeObject) {
3517
3628
  this.fabricCanvas.setActiveObject(activeObject);
3518
3629
  }
3519
- return replace(base64, /^data:.*;base64,/, "");
3630
+ return _.replace(base64, /^data:.*;base64,/, "");
3520
3631
  };
3521
3632
  /**
3522
3633
  * @override
@@ -3638,20 +3749,20 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3638
3749
  case ObjectType.BACKGROUND_IMAGE:
3639
3750
  return new BackgroundImage(this, fabricObject, persistedField);
3640
3751
  default:
3641
- throw new Error("Unknown field type: [" + persistedField.type + "]");
3752
+ throw new Error("Unknown field type: [".concat(persistedField.type, "]"));
3642
3753
  }
3643
3754
  };
3644
3755
  AbstractInteractiveCanvas.prototype.findFabricObject = function (id) {
3645
3756
  var objects = this.fabricCanvas.getObjects();
3646
- var fabricObject = find(objects, function (o) { return o.id == id; });
3757
+ var fabricObject = _.find(objects, function (o) { return o.id == id; });
3647
3758
  if (!fabricObject) {
3648
- throw new Error("Cannot find fabric object with id [" + id + "]");
3759
+ throw new Error("Cannot find fabric object with id [".concat(id, "]"));
3649
3760
  }
3650
3761
  return fabricObject;
3651
3762
  };
3652
3763
  AbstractInteractiveCanvas.prototype.findObject = function (id) {
3653
3764
  //Don't use strict compare here. fabric ids are numbers while ad builder ids are strings... mostly.
3654
- return find(this.objects$.value, function (object) { return object.getId() == id; });
3765
+ return _.find(this.objects$.value, function (object) { return object.getId() == id; });
3655
3766
  };
3656
3767
  /**
3657
3768
  * Reset zoom and canvas dimensions to 1:1 scale, execute a function, then return the canvas to
@@ -3689,7 +3800,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3689
3800
  if (!object) {
3690
3801
  return null;
3691
3802
  }
3692
- return find(this.objects$.value, function (field) { return field.getId() == object.id; });
3803
+ return _.find(this.objects$.value, function (field) { return field.getId() == object.id; });
3693
3804
  };
3694
3805
  AbstractInteractiveCanvas.prototype.getFieldsByCanvasObject = function (objects) {
3695
3806
  var _this = this;
@@ -3701,7 +3812,7 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3701
3812
  AbstractInteractiveCanvas.prototype.calculateImageCaptureCoefficient = function () {
3702
3813
  var precision = 3;
3703
3814
  var devicePixelRatio = this.devicePixelRatio || 1;
3704
- return round(2 / devicePixelRatio, precision);
3815
+ return _.round(2 / devicePixelRatio, precision);
3705
3816
  };
3706
3817
  AbstractInteractiveCanvas.prototype.randomId = function () {
3707
3818
  var min = 0;
@@ -3716,16 +3827,17 @@ var AbstractInteractiveCanvas = /** @class */ (function () {
3716
3827
  .reduce(function (x, y) { return Math.max(x, y); }, 0);
3717
3828
  };
3718
3829
  AbstractInteractiveCanvas.prototype.trackNewObject = function (object) {
3719
- this.objects$.next(__spreadArrays(this.objects$.value, [object]));
3830
+ this.objects$.next(__spreadArray(__spreadArray([], this.objects$.value, true), [object], false));
3720
3831
  };
3721
3832
  AbstractInteractiveCanvas.prototype.dimensionsExceedRestrictions = function (dimensions) {
3833
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
3722
3834
  var restrictions = this.dimensionRestrictions$.value;
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();
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);
3729
3841
  };
3730
3842
  return AbstractInteractiveCanvas;
3731
3843
  }());
@@ -3737,7 +3849,11 @@ var SelectionData = /** @class */ (function () {
3737
3849
  this.isText = selectedObject
3738
3850
  && selectedObject.getType() === ObjectType.TEXT
3739
3851
  && selectedObject.isEditing();
3852
+ this.event = {};
3740
3853
  }
3854
+ SelectionData.prototype.setEvent = function (event) {
3855
+ this.event = event;
3856
+ };
3741
3857
  return SelectionData;
3742
3858
  }());
3743
3859
 
@@ -3849,9 +3965,9 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3849
3965
  _this.headless = false;
3850
3966
  _this.undoStack = new UndoStack(_this);
3851
3967
  //Initialize watchers
3852
- _this.fabricCanvas.on("selection:updated", function () { return _this.onFabricSelectionChanged(); });
3853
- _this.fabricCanvas.on("selection:created", function () { return _this.onFabricSelectionChanged(); });
3854
- _this.fabricCanvas.on("selection:cleared", function () { return _this.onFabricSelectionChanged(); });
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); });
3855
3971
  _this.fabricCanvas.on("text:editing:entered", function () { return _this.onTextEditing(); });
3856
3972
  _this.fabricCanvas.on("text:editing:exited", function () { return _this.onTextEditing(); });
3857
3973
  _this.fabricCanvas.on("text:changed", function () { return _this.onTextChange(); });
@@ -3896,9 +4012,11 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3896
4012
  });
3897
4013
  });
3898
4014
  };
3899
- InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
4015
+ InteractiveCanvas.prototype.onFabricSelectionChanged = function (event) {
3900
4016
  var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
3901
- this.selection$.next(new SelectionData(selected));
4017
+ var selection = new SelectionData(selected);
4018
+ selection.setEvent(event);
4019
+ this.selection$.next(selection);
3902
4020
  this.enterTextSelectionModeIfRequired();
3903
4021
  };
3904
4022
  InteractiveCanvas.prototype.enterTextSelectionModeIfRequired = function () {
@@ -3916,80 +4034,4 @@ var InteractiveCanvas = /** @class */ (function (_super) {
3916
4034
  return InteractiveCanvas;
3917
4035
  }(AbstractInteractiveCanvas));
3918
4036
 
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
-
3995
4037
  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 };