@leapfrog/interactive-canvas 2.0.8 → 2.0.9-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/abstract-interactive-canvas.d.ts +372 -0
  2. package/dist/dimensions/millimeter-dimensions.d.ts +15 -0
  3. package/dist/dimensions/pixel-canvas-dimensions.d.ts +13 -0
  4. package/dist/dimensions/print-6-col-canvas-dimensions.d.ts +18 -0
  5. package/dist/dimensions/print-8-col-canvas-dimensions.d.ts +18 -0
  6. package/dist/font/font-library.d.ts +27 -0
  7. package/dist/font/font-library.interface.d.ts +24 -0
  8. package/dist/font/font.interface.d.ts +20 -0
  9. package/dist/font/unknown-font.d.ts +6 -0
  10. package/dist/headless-interactive-canvas.d.ts +10 -0
  11. package/dist/index.d.ts +54 -0
  12. package/dist/interactive-canvas.d.ts +25 -0
  13. package/dist/interactive-canvas.es.js +3995 -0
  14. package/dist/interactive-canvas.interface.d.ts +297 -0
  15. package/dist/interactive-canvas.js +4028 -0
  16. package/dist/layout/abstract-layout-manager.d.ts +17 -0
  17. package/dist/layout/advanced-layout-manager.d.ts +16 -0
  18. package/dist/layout/function/pin-to-bottom.layout-function.d.ts +4 -0
  19. package/dist/layout/function/redraw-all.layout-function.d.ts +4 -0
  20. package/dist/layout/function/reposition-backgrounds.layout-function.d.ts +4 -0
  21. package/dist/layout/function/reposition-borders.layout-function.d.ts +4 -0
  22. package/dist/layout/function/reposition-cutoffs.layout-function.d.ts +4 -0
  23. package/dist/layout/function/resize-canvas.layout-function.d.ts +4 -0
  24. package/dist/layout/function/stack-objects.layout-function.d.ts +11 -0
  25. package/dist/layout/function/update-object-dimensions.layout-function.d.ts +4 -0
  26. package/dist/layout/layout-manager.enum.d.ts +5 -0
  27. package/dist/layout/layout-manager.interface.d.ts +13 -0
  28. package/dist/layout/standard-layout-manager.d.ts +40 -0
  29. package/dist/mutator/mutable-background-color.interface.d.ts +15 -0
  30. package/dist/mutator/mutable-color.interface.d.ts +6 -0
  31. package/dist/mutator/mutable-image.interface.d.ts +28 -0
  32. package/dist/mutator/mutable-position.interface.d.ts +63 -0
  33. package/dist/mutator/mutable-stroke.interface.d.ts +8 -0
  34. package/dist/mutator/mutable-text-style.interface.d.ts +163 -0
  35. package/dist/mutator/mutable-text.interface.d.ts +80 -0
  36. package/dist/object/abstract-canvas-object.d.ts +207 -0
  37. package/dist/object/canvas-object-data.d.ts +24 -0
  38. package/dist/object/canvas-object.interface.d.ts +109 -0
  39. package/dist/object/impl/background-image.d.ts +38 -0
  40. package/dist/object/impl/border.d.ts +70 -0
  41. package/dist/object/impl/cutoff.d.ts +59 -0
  42. package/dist/object/impl/extended-fabric-object.interface.d.ts +7 -0
  43. package/dist/object/impl/extended-fabric-textbox.interface.d.ts +7 -0
  44. package/dist/object/impl/horizontal-rule.d.ts +83 -0
  45. package/dist/object/impl/image.d.ts +76 -0
  46. package/dist/object/impl/rectangle.d.ts +78 -0
  47. package/dist/object/impl/rich-text.d.ts +39 -0
  48. package/dist/object/impl/text.d.ts +314 -0
  49. package/dist/object/impl/vertical-rule.d.ts +83 -0
  50. package/dist/profile/canvas-profile.interface.d.ts +22 -0
  51. package/dist/profile/default-canvas-profile.d.ts +23 -0
  52. package/dist/types/canvas-dimension-restrictions.interface.d.ts +15 -0
  53. package/dist/types/canvas-dimensions.interface.d.ts +21 -0
  54. package/dist/types/canvas-state.interface.d.ts +11 -0
  55. package/dist/types/dimension-restrictions.interface.d.ts +6 -0
  56. package/dist/types/image-type.enum.d.ts +6 -0
  57. package/dist/types/margin.interface.d.ts +6 -0
  58. package/dist/types/object-dimensions.interface.d.ts +23 -0
  59. package/dist/types/object-type.enum.d.ts +12 -0
  60. package/dist/types/overflow.interface.d.ts +4 -0
  61. package/dist/types/position.interface.d.ts +9 -0
  62. package/dist/types/rect.interface.d.ts +6 -0
  63. package/dist/types/selection-data.interface.d.ts +19 -0
  64. package/dist/types/text-alignment.interface.d.ts +1 -0
  65. package/dist/undo-stack.d.ts +27 -0
  66. package/dist/undo-stack.interface.d.ts +6 -0
  67. package/package.json +30 -30
  68. package/readme.md +60 -60
@@ -0,0 +1,3995 @@
1
+ import * as _ from 'lodash';
2
+ import { round, each, values, reduce, clone, replace, find, isEqual } from 'lodash';
3
+ import { oc } from 'ts-optchain';
4
+ import { BehaviorSubject, Subject } from 'rxjs';
5
+ import { fabric } from 'fabric';
6
+
7
+ var PIXELS_PER_MM = 3.937;
8
+ var MillimeterDimensions = /** @class */ (function () {
9
+ function MillimeterDimensions(width, height) {
10
+ this.widthUnit = "mm";
11
+ this.heightUnit = "mm";
12
+ this.width = width;
13
+ this.widthMm = Math.max(0, width);
14
+ this.widthPx = round(this.widthMm * PIXELS_PER_MM);
15
+ this.height = height;
16
+ this.heightMm = Math.max(0, height);
17
+ this.heightPx = round(this.heightMm * PIXELS_PER_MM);
18
+ }
19
+ MillimeterDimensions.prototype.withSize = function (width, height) {
20
+ return new MillimeterDimensions(width, height);
21
+ };
22
+ MillimeterDimensions.prototype.widthPxToMm = function (px) {
23
+ return px / PIXELS_PER_MM;
24
+ };
25
+ MillimeterDimensions.prototype.heightPxToMm = function (px) {
26
+ return px / PIXELS_PER_MM;
27
+ };
28
+ return MillimeterDimensions;
29
+ }());
30
+
31
+ var PixelCanvasDimensions = /** @class */ (function () {
32
+ function PixelCanvasDimensions(width, height) {
33
+ this.widthUnit = "px";
34
+ this.heightUnit = "px";
35
+ this.width = width;
36
+ this.widthPx = width;
37
+ this.height = height;
38
+ this.heightPx = height;
39
+ }
40
+ PixelCanvasDimensions.prototype.withSize = function (width, height) {
41
+ return new PixelCanvasDimensions(width, height);
42
+ };
43
+ PixelCanvasDimensions.prototype.widthPxToMm = function (px) {
44
+ return void 0;
45
+ };
46
+ PixelCanvasDimensions.prototype.heightPxToMm = function (px) {
47
+ return void 0;
48
+ };
49
+ return PixelCanvasDimensions;
50
+ }());
51
+
52
+ var COLUMN_WIDTH_MM = 41;
53
+ var GUTTER_WIDTH_MM = 3;
54
+ var PIXELS_PER_MM$1 = 3.937;
55
+ var Print6ColCanvasDimensions = /** @class */ (function () {
56
+ function Print6ColCanvasDimensions(width, height) {
57
+ this.widthUnit = "column(s)";
58
+ this.heightUnit = "cm";
59
+ this.width = width;
60
+ this.gutterCount = Math.max(0, width - 1);
61
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
62
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM;
63
+ this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
64
+ this.widthPx = round(this.widthMm * PIXELS_PER_MM$1);
65
+ this.height = height;
66
+ this.heightMm = Math.max(0, height * 10);
67
+ this.heightPx = round(this.heightMm * PIXELS_PER_MM$1);
68
+ }
69
+ Print6ColCanvasDimensions.prototype.withSize = function (width, height) {
70
+ return new Print6ColCanvasDimensions(width, height);
71
+ };
72
+ Print6ColCanvasDimensions.prototype.widthPxToMm = function (px) {
73
+ return px / PIXELS_PER_MM$1;
74
+ };
75
+ Print6ColCanvasDimensions.prototype.heightPxToMm = function (px) {
76
+ return px / PIXELS_PER_MM$1;
77
+ };
78
+ return Print6ColCanvasDimensions;
79
+ }());
80
+
81
+ var COLUMN_WIDTH_MM$1 = 30.8772;
82
+ var GUTTER_WIDTH_MM$1 = 2.1053;
83
+ var PIXELS_PER_MM$2 = 3.937;
84
+ var Print8ColCanvasDimensions = /** @class */ (function () {
85
+ function Print8ColCanvasDimensions(width, height) {
86
+ this.widthUnit = "column(s)";
87
+ this.heightUnit = "cm";
88
+ this.width = width;
89
+ this.gutterCount = Math.max(0, width - 1);
90
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
91
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
92
+ this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
93
+ this.widthPx = round(this.widthMm * PIXELS_PER_MM$2);
94
+ this.height = height;
95
+ this.heightMm = Math.max(0, height * 10);
96
+ this.heightPx = round(this.heightMm * PIXELS_PER_MM$2);
97
+ }
98
+ Print8ColCanvasDimensions.prototype.withSize = function (width, height) {
99
+ return new Print8ColCanvasDimensions(width, height);
100
+ };
101
+ Print8ColCanvasDimensions.prototype.widthPxToMm = function (px) {
102
+ return px / PIXELS_PER_MM$2;
103
+ };
104
+ Print8ColCanvasDimensions.prototype.heightPxToMm = function (px) {
105
+ return px / PIXELS_PER_MM$2;
106
+ };
107
+ return Print8ColCanvasDimensions;
108
+ }());
109
+
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);
131
+ };
132
+
133
+ function __extends(d, b) {
134
+ extendStatics(d, b);
135
+ function __() { this.constructor = d; }
136
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
137
+ }
138
+
139
+ function __awaiter(thisArg, _arguments, P, generator) {
140
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
141
+ return new (P || (P = Promise))(function (resolve, reject) {
142
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
143
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
144
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
145
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
146
+ });
147
+ }
148
+
149
+ function __generator(thisArg, body) {
150
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
151
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
152
+ function verb(n) { return function (v) { return step([n, v]); }; }
153
+ function step(op) {
154
+ if (f) throw new TypeError("Generator is already executing.");
155
+ while (_) try {
156
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
157
+ if (y = 0, t) op = [op[0] & 2, t.value];
158
+ switch (op[0]) {
159
+ case 0: case 1: t = op; break;
160
+ case 4: _.label++; return { value: op[1], done: false };
161
+ case 5: _.label++; y = op[1]; op = [0]; continue;
162
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
163
+ default:
164
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
165
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
166
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
167
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
168
+ if (t[2]) _.ops.pop();
169
+ _.trys.pop(); continue;
170
+ }
171
+ op = body.call(thisArg, _);
172
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
173
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
174
+ }
175
+ }
176
+
177
+ function __spreadArrays() {
178
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
179
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
180
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
181
+ r[k] = a[j];
182
+ return r;
183
+ }
184
+
185
+ var Font = /** @class */ (function () {
186
+ function Font() {
187
+ }
188
+ /**
189
+ * @override
190
+ * @inheritDoc
191
+ */
192
+ Font.prototype.isBold = function (fontWeight) {
193
+ return fontWeight === this.boldWeight;
194
+ };
195
+ return Font;
196
+ }());
197
+
198
+ var UnknownFont = /** @class */ (function (_super) {
199
+ __extends(UnknownFont, _super);
200
+ function UnknownFont() {
201
+ var _this = _super !== null && _super.apply(this, arguments) || this;
202
+ _this.family = "_Unknown_";
203
+ _this.normalWeight = 400;
204
+ _this.boldWeight = 700;
205
+ return _this;
206
+ }
207
+ return UnknownFont;
208
+ }(Font));
209
+
210
+ var UNKNOWN_FONT = new UnknownFont();
211
+ var FontLibrary = /** @class */ (function () {
212
+ function FontLibrary() {
213
+ this._fonts = {};
214
+ }
215
+ /**
216
+ * @override
217
+ * @inheritDoc
218
+ */
219
+ FontLibrary.prototype.registerFont = function (font) {
220
+ this._fonts[font.family] = font;
221
+ };
222
+ /**
223
+ * @override
224
+ * @inheritDoc
225
+ */
226
+ FontLibrary.prototype.registerFonts = function (fonts) {
227
+ var _this = this;
228
+ each(fonts, function (font) { return _this._fonts[font.family] = font; });
229
+ };
230
+ /**
231
+ * @override
232
+ * @inheritDoc
233
+ */
234
+ FontLibrary.prototype.getFonts = function () {
235
+ return values(this._fonts);
236
+ };
237
+ /**
238
+ * @override
239
+ * @inheritDoc
240
+ */
241
+ FontLibrary.prototype.getFont = function (family) {
242
+ return this._fonts[family] || UNKNOWN_FONT;
243
+ };
244
+ return FontLibrary;
245
+ }());
246
+
247
+ var AbstractLayoutManager = /** @class */ (function () {
248
+ function AbstractLayoutManager(canvas) {
249
+ this.isEnforcedPositioning = false;
250
+ this.enterTextEditImmediatelyOnSelect = false;
251
+ this.canvas = canvas;
252
+ }
253
+ AbstractLayoutManager.prototype.getCanvas = function () {
254
+ return this.canvas;
255
+ };
256
+ AbstractLayoutManager.prototype.onInit = function () {
257
+ //noop
258
+ };
259
+ AbstractLayoutManager.prototype.onProfileChange = function (profile) {
260
+ //noop
261
+ };
262
+ AbstractLayoutManager.prototype.onCanvasDimensionsChange = function () {
263
+ //noop
264
+ };
265
+ AbstractLayoutManager.prototype.onTextChange = function () {
266
+ //noop
267
+ };
268
+ AbstractLayoutManager.prototype.onObjectListChange = function () {
269
+ //noop
270
+ };
271
+ AbstractLayoutManager.prototype.onMarginChange = function () {
272
+ //noop
273
+ };
274
+ return AbstractLayoutManager;
275
+ }());
276
+
277
+ var RedrawAllLayoutFunction = /** @class */ (function () {
278
+ function RedrawAllLayoutFunction() {
279
+ }
280
+ RedrawAllLayoutFunction.prototype.execute = function (canvas) {
281
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
282
+ canvas.redraw();
283
+ };
284
+ return RedrawAllLayoutFunction;
285
+ }());
286
+
287
+ var LayoutManager;
288
+ (function (LayoutManager) {
289
+ LayoutManager["LEGACY"] = "LEGACY";
290
+ LayoutManager["STANDARD"] = "STANDARD";
291
+ LayoutManager["ADVANCED"] = "ADVANCED";
292
+ })(LayoutManager || (LayoutManager = {}));
293
+
294
+ var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
295
+ function UpdateObjectDimensionsLayoutFunction() {
296
+ }
297
+ UpdateObjectDimensionsLayoutFunction.prototype.execute = function (canvas) {
298
+ canvas.getObjectsInternal().forEach(function (object) { return object.updateDimensions(); });
299
+ };
300
+ return UpdateObjectDimensionsLayoutFunction;
301
+ }());
302
+
303
+ var MIN_MAGNITUDE = 1;
304
+ var StackObjectsLayoutFunction = /** @class */ (function () {
305
+ function StackObjectsLayoutFunction() {
306
+ }
307
+ StackObjectsLayoutFunction.prototype.execute = function (canvas) {
308
+ var canvasMargin = canvas.getMargin();
309
+ var canvasDimensions = canvas.getDimensions();
310
+ var allObjects = canvas.getObjectsByTypesInternal(ObjectType.TEXT, ObjectType.RICH_TEXT, ObjectType.IMAGE, ObjectType.RECTANGLE, ObjectType.VERTICAL_RULE, ObjectType.HORIZONTAL_RULE);
311
+ var objects = _(allObjects)
312
+ .partition(function (object) { return object.isPinToBottom(); })
313
+ .value();
314
+ var footerObjects = objects[0];
315
+ var bodyObjects = objects[1];
316
+ var bodyWidth = canvasDimensions.widthPx - canvasMargin.right - canvasMargin.left;
317
+ canvas.redraw();
318
+ //Make one pass and set the widths of all elements. This will force objects with dynamic heights (like text) to take on their necessary height before trying to lay them out.
319
+ this.applyWidths(allObjects, bodyWidth);
320
+ var bodyRows = this.getRows(bodyObjects);
321
+ var footerRows = this.getRows(footerObjects);
322
+ var minimumHeight = canvasMargin.top + bodyRows.totalHeight + footerRows.totalHeight + canvasMargin.bottom;
323
+ this.adjustCanvasSize(canvas, minimumHeight);
324
+ this.layoutFooter(footerRows, canvas);
325
+ this.layoutBody(bodyRows, canvas, footerRows.totalHeight);
326
+ };
327
+ StackObjectsLayoutFunction.prototype.layoutFooter = function (footerRows, canvas) {
328
+ var canvasDimensions = canvas.getDimensions();
329
+ var canvasMargin = canvas.getMargin();
330
+ var layoutAreaWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
331
+ var nextObjectTop = canvasDimensions.heightPx - canvasMargin.bottom - footerRows.totalHeight;
332
+ var currentColumnWidthPercent = 0;
333
+ each(footerRows.rows, function (row) {
334
+ each(row.objects, function (object) {
335
+ var columnOffset = currentColumnWidthPercent / 100 * layoutAreaWidth;
336
+ var objectMargin = oc(object.getMargin()).left(0);
337
+ var left = canvasMargin.left + columnOffset + objectMargin;
338
+ if (object.getType() === ObjectType.VERTICAL_RULE)
339
+ object.setPosition({ height: row.height });
340
+ object.setPosition({
341
+ top: nextObjectTop + oc(object.getMargin()).top(0),
342
+ left: left
343
+ });
344
+ currentColumnWidthPercent += object.getColumnWidthPercent();
345
+ });
346
+ currentColumnWidthPercent = 0;
347
+ nextObjectTop += row.height;
348
+ });
349
+ };
350
+ StackObjectsLayoutFunction.prototype.layoutBody = function (bodyRows, canvas, footerHeight) {
351
+ var canvasDimensions = canvas.getDimensions();
352
+ var canvasMargin = canvas.getMargin();
353
+ var workableWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
354
+ var workableHeight = canvasDimensions.heightPx - canvasMargin.top - canvasMargin.bottom - footerHeight;
355
+ var leftoverSpace = workableHeight - bodyRows.totalHeight;
356
+ var spacesRequired = this.countSpaces(bodyRows);
357
+ var spaceSize = leftoverSpace / spacesRequired;
358
+ var nextObjectTop = canvasMargin.top;
359
+ var currentColumnWidthPercent = 0;
360
+ for (var i = 0; i < bodyRows.rows.length; i++) {
361
+ var row = bodyRows.rows[i];
362
+ var nextRow = bodyRows.rows[i + 1];
363
+ for (var _i = 0, _a = row.objects; _i < _a.length; _i++) {
364
+ var object = _a[_i];
365
+ var columnOffset = currentColumnWidthPercent / 100 * workableWidth;
366
+ var objectMargin = oc(object.getMargin()).left(0);
367
+ var objectLeft = canvasMargin.left + columnOffset + objectMargin;
368
+ if (object.getType() === ObjectType.TEXT && object.isBulleted())
369
+ objectLeft += object.getBulletMargin();
370
+ if (object.getType() === ObjectType.TEXT && object.isOrderedList())
371
+ objectLeft += object.getOrderedListMargin();
372
+ if (object.getType() === ObjectType.VERTICAL_RULE)
373
+ return;
374
+ object.setPosition({
375
+ top: nextObjectTop + oc(object.getMargin()).top(0),
376
+ left: objectLeft
377
+ });
378
+ currentColumnWidthPercent += object.getColumnWidthPercent();
379
+ }
380
+ currentColumnWidthPercent = 0;
381
+ nextObjectTop += row.height;
382
+ 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;
384
+ if (!thisRowIsHR && !nextRowIsHR) {
385
+ nextObjectTop += spaceSize;
386
+ }
387
+ }
388
+ };
389
+ StackObjectsLayoutFunction.prototype.applyWidths = function (objects, layoutWidth) {
390
+ _(objects).forEach(function (object) {
391
+ var targetWidth = object.getColumnWidthPercent() / 100 * layoutWidth;
392
+ var actualWidth = targetWidth - oc(object.getMargin()).left(0) - oc(object.getMargin()).right(0);
393
+ if (object.getType() === ObjectType.VERTICAL_RULE)
394
+ return;
395
+ if (object.getType() === ObjectType.TEXT && object.isBulleted())
396
+ actualWidth -= object.getBulletMargin();
397
+ if (object.getType() === ObjectType.TEXT && object.isOrderedList())
398
+ actualWidth -= object.getOrderedListMargin();
399
+ object.setPosition({
400
+ width: actualWidth
401
+ });
402
+ object.updateDimensions();
403
+ });
404
+ };
405
+ StackObjectsLayoutFunction.prototype.adjustCanvasSize = function (canvas, requiredHeight) {
406
+ if (oc(canvas.getDimensionsRestrictions()).fixed(false))
407
+ return;
408
+ var dimensions = canvas.getDimensions();
409
+ var minHeight = oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
410
+ var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
411
+ while (targetDimensions.heightPx < requiredHeight) {
412
+ targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
413
+ }
414
+ if (dimensions.height !== targetDimensions.height) {
415
+ canvas.setDimensions(targetDimensions);
416
+ }
417
+ };
418
+ StackObjectsLayoutFunction.prototype.getRows = function (objectsToLayout) {
419
+ var _this = this;
420
+ var result = { totalHeight: 0, rows: [] };
421
+ var currentWidth = 0;
422
+ var row = { objects: [], height: 1 };
423
+ each(objectsToLayout, function (object) {
424
+ var nextWidth = object.getColumnWidthPercent();
425
+ var objectHeight = _this.getObjectHeight(object);
426
+ if (currentWidth + nextWidth > 100) {
427
+ result.rows.push(row);
428
+ row = { objects: [], height: 1 };
429
+ currentWidth = 0;
430
+ }
431
+ row.objects.push(object);
432
+ if (object.getType() !== ObjectType.VERTICAL_RULE)
433
+ row.height = Math.max(row.height, objectHeight);
434
+ currentWidth += nextWidth;
435
+ });
436
+ if (row.objects.length)
437
+ result.rows.push(row);
438
+ result.totalHeight = reduce(result.rows, function (x, y) { return x + y.height; }, 0);
439
+ return result;
440
+ };
441
+ StackObjectsLayoutFunction.prototype.getObjectHeight = function (element) {
442
+ return element.getBoundingBox().height
443
+ + oc(element.getMargin()).top(0)
444
+ + oc(element.getMargin()).bottom(0);
445
+ };
446
+ StackObjectsLayoutFunction.prototype.countSpaces = function (rows) {
447
+ var count = 0;
448
+ for (var i = 0; i < rows.rows.length - 1; i++) {
449
+ var row = rows.rows[i];
450
+ var nextRow = rows.rows[i + 1];
451
+ 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;
453
+ if (!thisRowIsHR && !nextRowIsHR) {
454
+ count++;
455
+ }
456
+ }
457
+ return count;
458
+ };
459
+ return StackObjectsLayoutFunction;
460
+ }());
461
+
462
+ var RepositionBordersLayoutFunction = /** @class */ (function () {
463
+ function RepositionBordersLayoutFunction() {
464
+ }
465
+ RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
466
+ canvas.getObjectsByTypeInternal(ObjectType.BORDER)
467
+ .forEach(function (border) { return border.updatePosition(); });
468
+ };
469
+ return RepositionBordersLayoutFunction;
470
+ }());
471
+
472
+ var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
473
+ function RepositionBackgroundsLayoutFunction() {
474
+ }
475
+ RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
476
+ canvas.getObjectsByTypeInternal(ObjectType.BACKGROUND_IMAGE)
477
+ .forEach(function (border) { return border.updatePosition(); });
478
+ };
479
+ return RepositionBackgroundsLayoutFunction;
480
+ }());
481
+
482
+ var StandardLayoutManager = /** @class */ (function (_super) {
483
+ __extends(StandardLayoutManager, _super);
484
+ function StandardLayoutManager(canvas) {
485
+ var _this = _super.call(this, canvas) || this;
486
+ _this.key = LayoutManager.STANDARD;
487
+ _this.isEnforcedPositioning = true;
488
+ _this.enterTextEditImmediatelyOnSelect = true;
489
+ _this.redrawAll = new RedrawAllLayoutFunction();
490
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
491
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
492
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
493
+ _this.stackObjects = new StackObjectsLayoutFunction();
494
+ _this.updateObjectDimensions = new UpdateObjectDimensionsLayoutFunction();
495
+ return _this;
496
+ }
497
+ /**
498
+ * @override
499
+ */
500
+ StandardLayoutManager.prototype.onInit = function () {
501
+ this.stackAndRedraw();
502
+ };
503
+ /**
504
+ * @override
505
+ */
506
+ StandardLayoutManager.prototype.onProfileChange = function (profile) {
507
+ this.canvas.setMultiSelect(false);
508
+ this.redrawAll.execute(this.canvas);
509
+ };
510
+ /**
511
+ * @override
512
+ */
513
+ StandardLayoutManager.prototype.onCanvasDimensionsChange = function () {
514
+ this.repositionCutoffs.execute(this.canvas);
515
+ this.repositionBorders.execute(this.canvas);
516
+ this.repositionBackgrounds.execute(this.canvas);
517
+ };
518
+ /**
519
+ * @override
520
+ */
521
+ StandardLayoutManager.prototype.onTextChange = function () {
522
+ this.stackAndRedraw();
523
+ };
524
+ /**
525
+ * @override
526
+ */
527
+ StandardLayoutManager.prototype.onObjectListChange = function () {
528
+ this.stackAndRedraw();
529
+ };
530
+ /**
531
+ * @override
532
+ */
533
+ StandardLayoutManager.prototype.onMarginChange = function () {
534
+ this.stackAndRedraw();
535
+ };
536
+ StandardLayoutManager.prototype.stackAndRedraw = function () {
537
+ this.stackObjects.execute(this.canvas);
538
+ this.repositionCutoffs.execute(this.canvas);
539
+ this.repositionBorders.execute(this.canvas);
540
+ this.repositionBackgrounds.execute(this.canvas);
541
+ this.updateObjectDimensions.execute(this.canvas);
542
+ this.redrawAll.execute(this.canvas);
543
+ };
544
+ return StandardLayoutManager;
545
+ }(AbstractLayoutManager));
546
+
547
+ function isMutableBackgroundColor(object) {
548
+ return "setBackgroundColor" in object;
549
+ }
550
+
551
+ function isMutableColor(object) {
552
+ return "setColor" in object;
553
+ }
554
+
555
+ function isMutableImage(object) {
556
+ return "setImageUrl" in object;
557
+ }
558
+
559
+ function isMutablePosition(object) {
560
+ return "centerHorizontally" in object;
561
+ }
562
+
563
+ function isMutableStroke(object) {
564
+ return "setStrokeColor" in object;
565
+ }
566
+
567
+ function isMutableTextStyle(object) {
568
+ return "getTextSelection" in object;
569
+ }
570
+
571
+ function isMutableText(object) {
572
+ return "setText" in object;
573
+ }
574
+
575
+ /**
576
+ * Data for a persisted canvas object.
577
+ */
578
+ var CanvasObjectData = /** @class */ (function () {
579
+ function CanvasObjectData(type, id) {
580
+ this.id = id;
581
+ this.type = type;
582
+ }
583
+ return CanvasObjectData;
584
+ }());
585
+
586
+ var ROTATION_SNAP_ANGLE = 45;
587
+ var AbstractCanvasObject = /** @class */ (function () {
588
+ /**
589
+ * Create a new instance.
590
+ * @param type Object type.
591
+ * @param canvas Interactive canvas that the field will be rendered on.
592
+ * @param fabricObject The fabric object to bind this field to.
593
+ * @param data Existing persisted field data to load from, if applicable.
594
+ */
595
+ function AbstractCanvasObject(type, canvas, fabricObject, data) {
596
+ var _this = this;
597
+ this.canvas = canvas;
598
+ this.fabricObject = fabricObject;
599
+ this.data = data ? data : new CanvasObjectData(type, this.fabricObject.id);
600
+ this.dimensions$ = new BehaviorSubject(new FieldDimensions(this.fabricObject, this.canvas));
601
+ this.opacity$ = new BehaviorSubject(this.fabricObject.opacity);
602
+ this.updatePinToBottomDistance();
603
+ this.canvas.getProfile$().subscribe(function (profile) { return _this.onProfileChange(profile); });
604
+ this.canvas.getLayoutManager$().subscribe(function (layoutManager) { return _this.onLayoutManagerChange(layoutManager); });
605
+ this.fabricObject.on("moving", function (e) { return _this.onMove(e); });
606
+ this.fabricObject.on("rotating", function (e) { return _this.onRotate(e); });
607
+ this.fabricObject.on("scaling", function (e) { return _this.onScale(e); });
608
+ this.fabricObject.on("scaled", function (e) { return _this.afterScale(e); });
609
+ }
610
+ /**
611
+ * @override
612
+ * @inheritDoc
613
+ */
614
+ AbstractCanvasObject.prototype.getId = function () {
615
+ return this.data.id;
616
+ };
617
+ /**
618
+ * @override
619
+ * @inheritDoc
620
+ */
621
+ AbstractCanvasObject.prototype.getType = function () {
622
+ return this.data.type;
623
+ };
624
+ /**
625
+ * @override
626
+ * @inheritDoc
627
+ */
628
+ AbstractCanvasObject.prototype.getDescription = function () {
629
+ switch (this.data.type) {
630
+ case ObjectType.BORDER:
631
+ return "Border";
632
+ case ObjectType.CUTOFF:
633
+ return "Bottom Border";
634
+ case ObjectType.IMAGE:
635
+ return "Image";
636
+ case ObjectType.LIBRARY_IMAGE:
637
+ return "Library Image";
638
+ case ObjectType.RECTANGLE:
639
+ return "Rectangle";
640
+ case ObjectType.TEXT:
641
+ return "Text";
642
+ default:
643
+ return "Field";
644
+ }
645
+ };
646
+ /**
647
+ * @override
648
+ * @inheritDoc
649
+ */
650
+ AbstractCanvasObject.prototype.setSortCaption = function (value) {
651
+ this.data.sortCaption = value;
652
+ };
653
+ /**
654
+ * @override
655
+ * @inheritDoc
656
+ */
657
+ AbstractCanvasObject.prototype.isSortCaption = function () {
658
+ return this.data.sortCaption;
659
+ };
660
+ /**
661
+ * @override
662
+ * @inheritDoc
663
+ */
664
+ AbstractCanvasObject.prototype.getDimensions = function () {
665
+ return this.dimensions$.value;
666
+ };
667
+ /**
668
+ * @override
669
+ * @inheritDoc
670
+ */
671
+ AbstractCanvasObject.prototype.getDimensions$ = function () {
672
+ return this.dimensions$;
673
+ };
674
+ /**
675
+ * @override
676
+ * @inheritDoc
677
+ */
678
+ AbstractCanvasObject.prototype.getOpacity = function () {
679
+ return this.opacity$.value;
680
+ };
681
+ /**
682
+ * @override
683
+ * @inheritDoc
684
+ */
685
+ AbstractCanvasObject.prototype.getOpacity$ = function () {
686
+ return this.opacity$;
687
+ };
688
+ /**
689
+ * @override
690
+ * @inheritDoc
691
+ */
692
+ AbstractCanvasObject.prototype.setOpacity = function (value) {
693
+ this.fabricObject.set({ opacity: value });
694
+ this.opacity$.next(value);
695
+ this.redraw();
696
+ };
697
+ /**
698
+ * @override
699
+ * @inheritDoc
700
+ */
701
+ AbstractCanvasObject.prototype.getMargin = function () {
702
+ return this.data.margin || {
703
+ top: 0,
704
+ right: 0,
705
+ bottom: 0,
706
+ left: 0
707
+ };
708
+ };
709
+ /**
710
+ * @override
711
+ * @inheritDoc
712
+ */
713
+ AbstractCanvasObject.prototype.setMargin = function (margin) {
714
+ if (!margin)
715
+ return;
716
+ var newMargin = oc(this.data).margin({
717
+ top: 0,
718
+ right: 0,
719
+ bottom: 0,
720
+ left: 0
721
+ });
722
+ if (margin.top != undefined)
723
+ newMargin.top = margin.top || 0;
724
+ if (margin.right != undefined)
725
+ newMargin.right = margin.right || 0;
726
+ if (margin.bottom != undefined)
727
+ newMargin.bottom = margin.bottom || 0;
728
+ if (margin.left != undefined)
729
+ newMargin.left = margin.left || 0;
730
+ this.data.margin = newMargin;
731
+ this.canvas.notifyObjectListChanged();
732
+ };
733
+ /**
734
+ * @override
735
+ * @inheritDoc
736
+ */
737
+ AbstractCanvasObject.prototype.getColumnWidthPercent = function () {
738
+ return Math.max(Math.min(oc(this.data).columnWidthPercent(100), 100), 0);
739
+ };
740
+ /**
741
+ * @override
742
+ * @inheritDoc
743
+ */
744
+ AbstractCanvasObject.prototype.setColumnWidthPercent = function (percent) {
745
+ this.data.columnWidthPercent = percent;
746
+ this.canvas.notifyObjectListChanged();
747
+ };
748
+ /**
749
+ * @override
750
+ * @inheritDoc
751
+ */
752
+ AbstractCanvasObject.prototype.bringForward = function () {
753
+ this.fabricObject.bringForward();
754
+ this.canvas.syncObjectList();
755
+ };
756
+ /**
757
+ * @override
758
+ * @inheritDoc
759
+ */
760
+ AbstractCanvasObject.prototype.bringToFront = function () {
761
+ this.fabricObject.bringToFront();
762
+ this.canvas.syncObjectList();
763
+ };
764
+ /**
765
+ * @override
766
+ * @inheritDoc
767
+ */
768
+ AbstractCanvasObject.prototype.sendBackward = function () {
769
+ this.fabricObject.sendBackwards();
770
+ this.canvas.syncObjectList();
771
+ };
772
+ /**
773
+ * @override
774
+ * @inheritDoc
775
+ */
776
+ AbstractCanvasObject.prototype.sendToBack = function () {
777
+ this.fabricObject.sendToBack();
778
+ this.canvas.syncObjectList();
779
+ };
780
+ /**
781
+ * @override
782
+ * @inheritDoc
783
+ */
784
+ AbstractCanvasObject.prototype.moveUp = function () {
785
+ this.sendBackward();
786
+ };
787
+ /**
788
+ * @override
789
+ * @inheritDoc
790
+ */
791
+ AbstractCanvasObject.prototype.moveDown = function () {
792
+ this.bringForward();
793
+ };
794
+ /**
795
+ * @override
796
+ * @inheritDoc
797
+ */
798
+ AbstractCanvasObject.prototype.delete = function () {
799
+ this.canvas.removeObject(this);
800
+ this.onDelete();
801
+ };
802
+ /**
803
+ * @override
804
+ * @inheritDoc
805
+ */
806
+ AbstractCanvasObject.prototype.persist = function () {
807
+ return clone(this.data);
808
+ };
809
+ /**
810
+ * @override
811
+ * @inheritDoc
812
+ */
813
+ AbstractCanvasObject.prototype.isPinToBottom = function () {
814
+ return this.data.pinToBottom;
815
+ };
816
+ /**
817
+ * @override
818
+ * @inheritDoc
819
+ */
820
+ AbstractCanvasObject.prototype.setPinToBottom = function (value) {
821
+ if (value === void 0) { value = true; }
822
+ this.updatePinToBottomDistance();
823
+ this.data.pinToBottom = value;
824
+ this.canvas.notifyObjectListChanged();
825
+ this.updateFabricObjectBehavior();
826
+ };
827
+ /**
828
+ * @override
829
+ * @inheritDoc
830
+ */
831
+ AbstractCanvasObject.prototype.setLeft = function (left) {
832
+ this.setPosition({ left: left });
833
+ };
834
+ /**
835
+ * @override
836
+ * @inheritDoc
837
+ */
838
+ AbstractCanvasObject.prototype.setTop = function (top) {
839
+ this.setPosition({ top: top });
840
+ };
841
+ /**
842
+ * @override
843
+ * @inheritDoc
844
+ */
845
+ AbstractCanvasObject.prototype.setHeight = function (height) {
846
+ this.setPosition({ height: height });
847
+ };
848
+ /**
849
+ * @override
850
+ * @inheritDoc
851
+ */
852
+ AbstractCanvasObject.prototype.setWidth = function (width) {
853
+ this.setPosition({ width: width });
854
+ };
855
+ /**
856
+ * @override
857
+ * @inheritDoc
858
+ */
859
+ AbstractCanvasObject.prototype.setAngle = function (angle) {
860
+ this.setPosition({ angle: angle });
861
+ };
862
+ /**
863
+ * @override
864
+ * @inheritDoc
865
+ */
866
+ AbstractCanvasObject.prototype.setScaleX = function (scale) {
867
+ this.setPosition({ scaleX: scale });
868
+ };
869
+ /**
870
+ * @override
871
+ * @inheritDoc
872
+ */
873
+ AbstractCanvasObject.prototype.setScaleY = function (scale) {
874
+ this.setPosition({ scaleY: scale });
875
+ };
876
+ /**
877
+ * Get the underlying fabric object.
878
+ * (Internal use only, do not expose this outside the canvas module).
879
+ */
880
+ AbstractCanvasObject.prototype.getFabricObjectInternal = function () {
881
+ return this.fabricObject;
882
+ };
883
+ AbstractCanvasObject.prototype.setPosition = function (position) {
884
+ var scale = this.getDimensions().scale;
885
+ if (position.top != undefined)
886
+ this.fabricObject.set({ top: position.top });
887
+ if (position.left != undefined)
888
+ this.fabricObject.set({ left: position.left });
889
+ if (position.width != undefined)
890
+ this.fabricObject.set({ width: position.width / scale.x });
891
+ if (position.height != undefined)
892
+ this.fabricObject.set({ height: position.height / scale.y });
893
+ if (position.angle != undefined)
894
+ this.fabricObject.set({ angle: position.angle });
895
+ if (position.scaleX != undefined)
896
+ this.fabricObject.set({ scaleX: position.scaleX });
897
+ if (position.scaleY != undefined)
898
+ this.fabricObject.set({ scaleY: position.scaleY });
899
+ this.setCoords();
900
+ this.redraw();
901
+ };
902
+ AbstractCanvasObject.prototype.setCoords = function () {
903
+ this.fabricObject.setCoords();
904
+ };
905
+ AbstractCanvasObject.prototype.updateDimensions = function () {
906
+ this.setCoords();
907
+ var dimensions = new FieldDimensions(this.fabricObject, this.canvas);
908
+ this.dimensions$.next(dimensions);
909
+ };
910
+ AbstractCanvasObject.prototype.getBoundingBox = function () {
911
+ var absolute = true;
912
+ var calculate = true;
913
+ return this.fabricObject.getBoundingRect(absolute, calculate);
914
+ };
915
+ AbstractCanvasObject.prototype.moveToPinnedPosition = function () {
916
+ if (this.data.pinToBottom) {
917
+ this.setPosition({
918
+ top: this.canvas.getDimensions().heightPx - this.pinToBottomDistance
919
+ });
920
+ }
921
+ };
922
+ AbstractCanvasObject.prototype.updatePinToBottomDistance = function () {
923
+ this.pinToBottomDistance = this.canvas.getDimensions().heightPx - this.getDimensions().top.px;
924
+ };
925
+ AbstractCanvasObject.prototype.redraw = function () {
926
+ this.canvas.redraw();
927
+ };
928
+ // noinspection JSUnusedLocalSymbols
929
+ AbstractCanvasObject.prototype.onProfileChange = function (profile) {
930
+ this.updateFabricObjectBehavior();
931
+ this.redraw();
932
+ };
933
+ // noinspection JSUnusedLocalSymbols
934
+ AbstractCanvasObject.prototype.onLayoutManagerChange = function (layoutManager) {
935
+ this.updateFabricObjectBehavior();
936
+ this.redraw();
937
+ };
938
+ // noinspection JSUnusedLocalSymbols
939
+ AbstractCanvasObject.prototype.onMove = function (event) {
940
+ if (!this.canvas.getProfile().allowObjectsToLeaveCanvas) {
941
+ this.preventLeavingCanvas();
942
+ }
943
+ this.updateDimensions();
944
+ };
945
+ AbstractCanvasObject.prototype.onRotate = function (event) {
946
+ if (event.e.shiftKey) {
947
+ this.fabricObject.set({ snapAngle: 0 });
948
+ }
949
+ else {
950
+ this.fabricObject.set({ snapAngle: ROTATION_SNAP_ANGLE });
951
+ }
952
+ this.updateDimensions();
953
+ };
954
+ // noinspection JSUnusedLocalSymbols
955
+ AbstractCanvasObject.prototype.onScale = function (event) {
956
+ this.updateDimensions();
957
+ };
958
+ // noinspection JSUnusedLocalSymbols
959
+ AbstractCanvasObject.prototype.afterScale = function (event) {
960
+ this.updateDimensions();
961
+ };
962
+ AbstractCanvasObject.prototype.onDelete = function () {
963
+ //no-op
964
+ };
965
+ AbstractCanvasObject.prototype.preventLeavingCanvas = function () {
966
+ var overflow = this.getCanvasOverflow();
967
+ if (overflow.hasOverflow) {
968
+ var adjustX = overflow.left || -overflow.right;
969
+ var adjustY = overflow.top || -overflow.bottom;
970
+ this.fabricObject.set({
971
+ top: this.fabricObject.top + adjustY,
972
+ left: this.fabricObject.left + adjustX
973
+ });
974
+ this.redraw();
975
+ }
976
+ };
977
+ AbstractCanvasObject.prototype.getCanvasOverflow = function () {
978
+ var bound = this.getBoundingBox();
979
+ var canvasDimensions = this.canvas.getDimensions();
980
+ var top = Math.max(0, 0 - bound.top);
981
+ var right = Math.max(0, bound.left + bound.width - canvasDimensions.widthPx);
982
+ var bottom = Math.max(0, bound.top + bound.height - canvasDimensions.heightPx);
983
+ var left = Math.max(0, 0 - bound.left);
984
+ return {
985
+ top: top,
986
+ right: right,
987
+ bottom: bottom,
988
+ left: left,
989
+ hasOverflow: top > 0 || right > 0 || bottom > 0 || left > 0
990
+ };
991
+ };
992
+ AbstractCanvasObject.prototype.centerHorizontallyInternal = function () {
993
+ var canvasWidth = this.canvas.getDimensions().widthPx;
994
+ var objectWidth = this.getDimensions().width.px;
995
+ this.fabricObject.set({ left: ((canvasWidth - objectWidth) / 2) - 0.5 });
996
+ this.updateDimensions();
997
+ this.redraw();
998
+ };
999
+ AbstractCanvasObject.prototype.centerVerticallyInternal = function () {
1000
+ var canvasHeight = this.canvas.getDimensions().heightPx;
1001
+ var objectHeight = this.getDimensions().height.px;
1002
+ this.fabricObject.set({ top: ((canvasHeight - objectHeight) / 2) - 0.5 });
1003
+ this.redraw();
1004
+ this.updateDimensions();
1005
+ };
1006
+ AbstractCanvasObject.prototype.nudgeInternal = function (x, y) {
1007
+ if (x === void 0) { x = 0; }
1008
+ if (y === void 0) { y = 0; }
1009
+ this.fabricObject.set({
1010
+ top: this.getDimensions().top.px + y,
1011
+ left: this.getDimensions().left.px + x
1012
+ });
1013
+ this.redraw();
1014
+ this.updateDimensions();
1015
+ };
1016
+ AbstractCanvasObject.prototype.updateFabricObjectBehavior = function () {
1017
+ var allowManualPositioning = !this.canvas.getLayoutManager().isEnforcedPositioning;
1018
+ var profile = this.canvas.getProfile();
1019
+ var options = {
1020
+ allowMove: allowManualPositioning && profile.allowMove && !this.isPinToBottom(),
1021
+ allowRotate: allowManualPositioning && profile.allowRotate && !this.isPinToBottom(),
1022
+ allowScale: allowManualPositioning && profile.allowScale && !this.isPinToBottom()
1023
+ };
1024
+ this.fabricObject.set({
1025
+ lockMovementX: !options.allowMove,
1026
+ lockMovementY: !options.allowMove,
1027
+ lockScalingX: !options.allowScale,
1028
+ lockScalingY: !options.allowScale,
1029
+ lockScalingFlip: true,
1030
+ lockRotation: !options.allowRotate
1031
+ });
1032
+ this.fabricObject.setControlsVisibility({
1033
+ tl: options.allowScale,
1034
+ tr: options.allowScale,
1035
+ br: options.allowScale,
1036
+ bl: options.allowScale,
1037
+ ml: options.allowScale,
1038
+ mt: options.allowScale,
1039
+ mr: options.allowScale,
1040
+ mb: options.allowScale,
1041
+ mtr: options.allowRotate
1042
+ });
1043
+ };
1044
+ return AbstractCanvasObject;
1045
+ }());
1046
+ var FieldDimensions = /** @class */ (function () {
1047
+ function FieldDimensions(fabricObject, canvas) {
1048
+ var widthPxToMmFunction = canvas.getDimensions().widthPxToMm;
1049
+ var heightPxToMmFunction = canvas.getDimensions().heightPxToMm;
1050
+ this.top = { px: fabricObject.top, mm: heightPxToMmFunction(fabricObject.top) };
1051
+ this.left = { px: fabricObject.left, mm: widthPxToMmFunction(fabricObject.left) };
1052
+ var widthPx = fabricObject.width * fabricObject.scaleX;
1053
+ var heightPx = fabricObject.height * fabricObject.scaleY;
1054
+ this.width = { px: widthPx, mm: widthPxToMmFunction(widthPx) };
1055
+ this.height = { px: heightPx, mm: heightPxToMmFunction(heightPx) };
1056
+ this.scale = { x: fabricObject.scaleX, y: fabricObject.scaleY };
1057
+ this.angle = fabricObject.angle;
1058
+ }
1059
+ return FieldDimensions;
1060
+ }());
1061
+
1062
+ var BackgroundImage = /** @class */ (function (_super) {
1063
+ __extends(BackgroundImage, _super);
1064
+ function BackgroundImage(canvas, fabricObject, persistedField) {
1065
+ var _this = _super.call(this, ObjectType.BACKGROUND_IMAGE, canvas, fabricObject, persistedField) || this;
1066
+ _this.imageUrl$ = new BehaviorSubject(_this.fabricObject.getSrc());
1067
+ _this.data.imagePath = _this.imageUrl$.value;
1068
+ _this.updatePosition();
1069
+ return _this;
1070
+ }
1071
+ BackgroundImage.prototype.updatePosition = function () {
1072
+ var _a = this.canvas.getDimensions(), widthPx = _a.widthPx, heightPx = _a.heightPx;
1073
+ this.fabricObject.set({
1074
+ top: 0,
1075
+ left: 0,
1076
+ scaleX: widthPx / this.fabricObject.width,
1077
+ scaleY: heightPx / this.fabricObject.height
1078
+ });
1079
+ this.fabricObject.sendToBack();
1080
+ this.updateDimensions();
1081
+ };
1082
+ /**
1083
+ * @override
1084
+ * @inheritDoc
1085
+ */
1086
+ BackgroundImage.prototype.updateFabricObjectBehavior = function () {
1087
+ _super.prototype.updateFabricObjectBehavior.call(this);
1088
+ this.fabricObject.set({
1089
+ lockMovementX: true,
1090
+ lockMovementY: true,
1091
+ lockScalingX: true,
1092
+ lockScalingY: true,
1093
+ lockScalingFlip: true
1094
+ });
1095
+ this.fabricObject.setControlsVisibility({
1096
+ tl: false,
1097
+ tr: false,
1098
+ br: false,
1099
+ bl: false,
1100
+ ml: false,
1101
+ mt: false,
1102
+ mr: false,
1103
+ mb: false,
1104
+ mtr: false
1105
+ });
1106
+ this.redraw();
1107
+ };
1108
+ /**
1109
+ * @override
1110
+ * @inheritDoc
1111
+ */
1112
+ BackgroundImage.prototype.getImageUrl = function () {
1113
+ return this.imageUrl$.value;
1114
+ };
1115
+ /**
1116
+ * @override
1117
+ * @inheritDoc
1118
+ */
1119
+ BackgroundImage.prototype.getImageUrl$ = function () {
1120
+ return this.imageUrl$;
1121
+ };
1122
+ /**
1123
+ * @override
1124
+ * @inheritDoc
1125
+ */
1126
+ BackgroundImage.prototype.setImageUrl = function (url) {
1127
+ return __awaiter(this, void 0, void 0, function () {
1128
+ return __generator(this, function (_a) {
1129
+ switch (_a.label) {
1130
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1131
+ case 1:
1132
+ _a.sent();
1133
+ this.data.imagePath = url;
1134
+ this.imageUrl$.next(url);
1135
+ this.canvas.notifyObjectListChanged();
1136
+ return [2 /*return*/];
1137
+ }
1138
+ });
1139
+ });
1140
+ };
1141
+ /**
1142
+ * @override
1143
+ * @inheritDoc
1144
+ */
1145
+ BackgroundImage.prototype.setImageWidth = function (px, sizeRestrictions) {
1146
+ return 0; //no-op
1147
+ };
1148
+ BackgroundImage.prototype.setCanvasImage = function (url) {
1149
+ return __awaiter(this, void 0, void 0, function () {
1150
+ var imageOptions, _a, widthPx, heightPx;
1151
+ var _this = this;
1152
+ return __generator(this, function (_b) {
1153
+ switch (_b.label) {
1154
+ case 0:
1155
+ imageOptions = { crossOrigin: "anonymous" };
1156
+ _a = this.canvas.getDimensions(), widthPx = _a.widthPx, heightPx = _a.heightPx;
1157
+ return [4 /*yield*/, new Promise(function (resolve) {
1158
+ _this.fabricObject.setSrc(url, function (img) {
1159
+ img.scaleToWidth(widthPx);
1160
+ img.scaleToHeight(heightPx);
1161
+ img.setCoords();
1162
+ _this.redraw();
1163
+ resolve();
1164
+ }, imageOptions);
1165
+ })];
1166
+ case 1: return [2 /*return*/, _b.sent()];
1167
+ }
1168
+ });
1169
+ });
1170
+ };
1171
+ return BackgroundImage;
1172
+ }(AbstractCanvasObject));
1173
+
1174
+ var Border = /** @class */ (function (_super) {
1175
+ __extends(Border, _super);
1176
+ function Border(canvas, fabricObject, persistedField) {
1177
+ var _this = _super.call(this, ObjectType.BORDER, canvas, fabricObject, persistedField) || this;
1178
+ _this.strokeWidth$ = new BehaviorSubject(0);
1179
+ _this.canvas = canvas;
1180
+ _this.strokeWidth$.next(_this.fabricObject.strokeWidth);
1181
+ _this.fabricObject.set({ "fill": null });
1182
+ _this.updatePosition();
1183
+ return _this;
1184
+ }
1185
+ /**
1186
+ * @override
1187
+ * @inheritDoc
1188
+ */
1189
+ Border.prototype.getColor = function () {
1190
+ return this.fabricObject.stroke;
1191
+ };
1192
+ /**
1193
+ * @override
1194
+ * @inheritDoc
1195
+ */
1196
+ Border.prototype.setColor = function (color) {
1197
+ this.fabricObject.set({ stroke: color });
1198
+ this.data.color = color;
1199
+ this.redraw();
1200
+ };
1201
+ /**
1202
+ * @override
1203
+ * @inheritDoc
1204
+ */
1205
+ Border.prototype.getStrokeWidth = function () {
1206
+ return this.fabricObject.strokeWidth;
1207
+ };
1208
+ /**
1209
+ * @override
1210
+ * @inheritDoc
1211
+ */
1212
+ Border.prototype.getStrokeWidth$ = function () {
1213
+ return this.strokeWidth$;
1214
+ };
1215
+ /**
1216
+ * @override
1217
+ * @inheritDoc
1218
+ */
1219
+ Border.prototype.setStrokeWidth = function (width) {
1220
+ this.strokeWidth$.next(width);
1221
+ this.data.strokeWidth = width;
1222
+ this.updatePosition();
1223
+ this.canvas.notifyMarginChanged();
1224
+ this.redraw();
1225
+ };
1226
+ Border.prototype.getPadding = function () {
1227
+ return this.data.padding || {
1228
+ top: 0,
1229
+ right: 0,
1230
+ bottom: 0,
1231
+ left: 0
1232
+ };
1233
+ };
1234
+ Border.prototype.setPadding = function (padding) {
1235
+ if (!padding)
1236
+ return;
1237
+ this.data.padding = {
1238
+ top: padding.top || 0,
1239
+ right: padding.right || 0,
1240
+ bottom: padding.bottom || 0,
1241
+ left: padding.left || 0
1242
+ };
1243
+ this.canvas.notifyMarginChanged();
1244
+ this.redraw();
1245
+ };
1246
+ Border.prototype.updatePosition = function () {
1247
+ this.fabricObject.set({
1248
+ strokeWidth: this.strokeWidth$.value,
1249
+ top: 0,
1250
+ left: 0,
1251
+ width: this.canvas.getDimensions().widthPx - this.strokeWidth$.value,
1252
+ height: this.canvas.getDimensions().heightPx - this.strokeWidth$.value
1253
+ });
1254
+ };
1255
+ /**
1256
+ * @override
1257
+ * @inheritDoc
1258
+ */
1259
+ Border.prototype.updateFabricObjectBehavior = function () {
1260
+ _super.prototype.updateFabricObjectBehavior.call(this);
1261
+ this.fabricObject.set({
1262
+ lockMovementX: true,
1263
+ lockMovementY: true,
1264
+ lockScalingX: true,
1265
+ lockScalingY: true,
1266
+ lockScalingFlip: true
1267
+ });
1268
+ this.fabricObject.setControlsVisibility({
1269
+ tl: false,
1270
+ tr: false,
1271
+ br: false,
1272
+ bl: false,
1273
+ ml: false,
1274
+ mt: false,
1275
+ mr: false,
1276
+ mb: false,
1277
+ mtr: false
1278
+ });
1279
+ this.redraw();
1280
+ };
1281
+ return Border;
1282
+ }(AbstractCanvasObject));
1283
+
1284
+ var Cutoff = /** @class */ (function (_super) {
1285
+ __extends(Cutoff, _super);
1286
+ function Cutoff(canvas, fabricObject, persistedField) {
1287
+ var _this = _super.call(this, ObjectType.CUTOFF, canvas, fabricObject, persistedField) || this;
1288
+ _this.strokeWidth$ = new BehaviorSubject(0);
1289
+ _this.canvas = canvas;
1290
+ _this.strokeWidth$.next(_this.fabricObject.height);
1291
+ _this.updatePosition();
1292
+ _this.fabricObject.set({ strokeWidth: 0 });
1293
+ return _this;
1294
+ }
1295
+ /**
1296
+ * @override
1297
+ * @inheritDoc
1298
+ */
1299
+ Cutoff.prototype.getColor = function () {
1300
+ return this.fabricObject.fill;
1301
+ };
1302
+ /**
1303
+ * @override
1304
+ * @inheritDoc
1305
+ */
1306
+ Cutoff.prototype.setColor = function (color) {
1307
+ this.fabricObject.set({ fill: color, stroke: color });
1308
+ this.data.color = color;
1309
+ this.redraw();
1310
+ };
1311
+ /**
1312
+ * @override
1313
+ * @inheritDoc
1314
+ */
1315
+ Cutoff.prototype.getStrokeWidth = function () {
1316
+ // noinspection JSSuspiciousNameCombination
1317
+ return this.fabricObject.height;
1318
+ };
1319
+ /**
1320
+ * @override
1321
+ * @inheritDoc
1322
+ */
1323
+ Cutoff.prototype.getStrokeWidth$ = function () {
1324
+ return this.strokeWidth$;
1325
+ };
1326
+ /**
1327
+ * @override
1328
+ * @inheritDoc
1329
+ */
1330
+ Cutoff.prototype.setStrokeWidth = function (width) {
1331
+ this.strokeWidth$.next(width);
1332
+ this.data.strokeWidth = width;
1333
+ this.updatePosition();
1334
+ this.canvas.notifyMarginChanged();
1335
+ this.redraw();
1336
+ };
1337
+ Cutoff.prototype.updatePosition = function () {
1338
+ this.fabricObject.set({
1339
+ top: this.canvas.getDimensions().heightPx - this.strokeWidth$.value,
1340
+ left: 0,
1341
+ width: this.canvas.getDimensions().widthPx,
1342
+ height: this.strokeWidth$.value
1343
+ });
1344
+ };
1345
+ /**
1346
+ * @override
1347
+ * @inheritDoc
1348
+ */
1349
+ Cutoff.prototype.updateFabricObjectBehavior = function () {
1350
+ this.fabricObject.set({
1351
+ lockMovementX: true,
1352
+ lockMovementY: true,
1353
+ lockScalingX: true,
1354
+ lockScalingY: true,
1355
+ lockScalingFlip: true
1356
+ });
1357
+ this.fabricObject.setControlsVisibility({
1358
+ tl: false,
1359
+ tr: false,
1360
+ br: false,
1361
+ bl: false,
1362
+ ml: false,
1363
+ mt: false,
1364
+ mr: false,
1365
+ mb: false,
1366
+ mtr: false
1367
+ });
1368
+ this.redraw();
1369
+ };
1370
+ return Cutoff;
1371
+ }(AbstractCanvasObject));
1372
+
1373
+ var HorizontalRule = /** @class */ (function (_super) {
1374
+ __extends(HorizontalRule, _super);
1375
+ function HorizontalRule(canvas, fabricObject, persistedField) {
1376
+ var _this = _super.call(this, ObjectType.HORIZONTAL_RULE, canvas, fabricObject, persistedField) || this;
1377
+ _this.strokeWidth$ = new BehaviorSubject(2);
1378
+ _this.canvas = canvas;
1379
+ _this.strokeWidth$.next(_this.getDimensions().height.px);
1380
+ _this.fabricObject.set({ strokeWidth: 0 });
1381
+ return _this;
1382
+ }
1383
+ /**
1384
+ * @override
1385
+ * @inheritDoc
1386
+ */
1387
+ HorizontalRule.prototype.getStrokeWidth = function () {
1388
+ // noinspection JSSuspiciousNameCombination
1389
+ return this.fabricObject.height;
1390
+ };
1391
+ /**
1392
+ * @override
1393
+ * @inheritDoc
1394
+ */
1395
+ HorizontalRule.prototype.getStrokeWidth$ = function () {
1396
+ return this.strokeWidth$;
1397
+ };
1398
+ /**
1399
+ * @override
1400
+ * @inheritDoc
1401
+ */
1402
+ HorizontalRule.prototype.setStrokeWidth = function (value) {
1403
+ this.strokeWidth$.next(value);
1404
+ this.data.strokeWidth = value;
1405
+ this.setPosition({ height: value });
1406
+ this.canvas.notifyObjectListChanged();
1407
+ this.redraw();
1408
+ };
1409
+ /**
1410
+ * @override
1411
+ * @inheritDoc
1412
+ */
1413
+ HorizontalRule.prototype.getColor = function () {
1414
+ return this.fabricObject.fill;
1415
+ };
1416
+ /**
1417
+ * @override
1418
+ * @inheritDoc
1419
+ */
1420
+ HorizontalRule.prototype.setColor = function (color) {
1421
+ this.fabricObject.set({ fill: color, stroke: color });
1422
+ this.data.color = color;
1423
+ this.redraw();
1424
+ };
1425
+ /**
1426
+ * @override
1427
+ * @inheritDoc
1428
+ */
1429
+ HorizontalRule.prototype.centerHorizontally = function () {
1430
+ _super.prototype.centerHorizontallyInternal.call(this);
1431
+ };
1432
+ /**
1433
+ * @override
1434
+ * @inheritDoc
1435
+ */
1436
+ HorizontalRule.prototype.centerVertically = function () {
1437
+ _super.prototype.centerVerticallyInternal.call(this);
1438
+ };
1439
+ /**
1440
+ * @override
1441
+ * @inheritDoc
1442
+ */
1443
+ HorizontalRule.prototype.nudgeUp = function () {
1444
+ _super.prototype.nudgeInternal.call(this, 0, -1);
1445
+ };
1446
+ /**
1447
+ * @override
1448
+ * @inheritDoc
1449
+ */
1450
+ HorizontalRule.prototype.nudgeDown = function () {
1451
+ _super.prototype.nudgeInternal.call(this, 0, +1);
1452
+ };
1453
+ /**
1454
+ * @override
1455
+ * @inheritDoc
1456
+ */
1457
+ HorizontalRule.prototype.nudgeLeft = function () {
1458
+ _super.prototype.nudgeInternal.call(this, -1, 0);
1459
+ };
1460
+ /**
1461
+ * @override
1462
+ * @inheritDoc
1463
+ */
1464
+ HorizontalRule.prototype.nudgeRight = function () {
1465
+ _super.prototype.nudgeInternal.call(this, +1, 0);
1466
+ };
1467
+ return HorizontalRule;
1468
+ }(AbstractCanvasObject));
1469
+
1470
+ var Image = /** @class */ (function (_super) {
1471
+ __extends(Image, _super);
1472
+ function Image(canvas, fabricObject, persistedField) {
1473
+ var _this = _super.call(this, ObjectType.IMAGE, canvas, fabricObject, persistedField) || this;
1474
+ _this.DEFAULT_RESTRICTIONS = {
1475
+ minWidth: 1,
1476
+ minHeight: 1
1477
+ };
1478
+ _this.canvas = canvas;
1479
+ _this.imageUrl$ = new BehaviorSubject(_this.fabricObject.getSrc());
1480
+ _this.data.imagePath = _this.imageUrl$.value;
1481
+ _this.layoutWidth = _this.getBoundingBox().width;
1482
+ return _this;
1483
+ }
1484
+ /**
1485
+ * @override
1486
+ * @inheritDoc
1487
+ */
1488
+ Image.prototype.getImageUrl = function () {
1489
+ return this.imageUrl$.value;
1490
+ };
1491
+ /**
1492
+ * @override
1493
+ * @inheritDoc
1494
+ */
1495
+ Image.prototype.getImageUrl$ = function () {
1496
+ return this.imageUrl$;
1497
+ };
1498
+ /**
1499
+ * @override
1500
+ * @inheritDoc
1501
+ */
1502
+ Image.prototype.setImageUrl = function (url) {
1503
+ return __awaiter(this, void 0, void 0, function () {
1504
+ return __generator(this, function (_a) {
1505
+ switch (_a.label) {
1506
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1507
+ case 1:
1508
+ _a.sent();
1509
+ this.data.imagePath = url;
1510
+ this.imageUrl$.next(url);
1511
+ this.canvas.notifyObjectListChanged();
1512
+ return [2 /*return*/];
1513
+ }
1514
+ });
1515
+ });
1516
+ };
1517
+ /**
1518
+ * @override
1519
+ * @inheritDoc
1520
+ */
1521
+ Image.prototype.setImageWidth = function (px, sizeRestrictions) {
1522
+ if (sizeRestrictions === void 0) { sizeRestrictions = this.DEFAULT_RESTRICTIONS; }
1523
+ var minWidth = Math.max(sizeRestrictions.minWidth, this.getMinWidthBasedOnMinHeight(sizeRestrictions.minHeight));
1524
+ var maxWidth = Math.min(sizeRestrictions.maxWidth, this.getMaxWidthBasedOnMaxHeight(sizeRestrictions.maxHeight));
1525
+ if (px < minWidth) {
1526
+ px = minWidth;
1527
+ }
1528
+ else if (px > maxWidth) {
1529
+ px = maxWidth;
1530
+ }
1531
+ var premultipliedWidth = this.fabricObject.width;
1532
+ var newScale = (premultipliedWidth > 0) ? px / premultipliedWidth : 1;
1533
+ this.fabricObject.set({ scaleX: newScale, scaleY: newScale });
1534
+ this.setCoords();
1535
+ this.canvas.notifyObjectListChanged();
1536
+ return px;
1537
+ };
1538
+ /**
1539
+ * @override
1540
+ * @inheritDoc
1541
+ */
1542
+ Image.prototype.centerHorizontally = function () {
1543
+ _super.prototype.centerHorizontallyInternal.call(this);
1544
+ };
1545
+ /**
1546
+ * @override
1547
+ * @inheritDoc
1548
+ */
1549
+ Image.prototype.centerVertically = function () {
1550
+ _super.prototype.centerVerticallyInternal.call(this);
1551
+ };
1552
+ /**
1553
+ * @override
1554
+ * @inheritDoc
1555
+ */
1556
+ Image.prototype.nudgeUp = function () {
1557
+ _super.prototype.nudgeInternal.call(this, 0, -1);
1558
+ };
1559
+ /**
1560
+ * @override
1561
+ * @inheritDoc
1562
+ */
1563
+ Image.prototype.nudgeDown = function () {
1564
+ _super.prototype.nudgeInternal.call(this, 0, +1);
1565
+ };
1566
+ /**
1567
+ * @override
1568
+ * @inheritDoc
1569
+ */
1570
+ Image.prototype.nudgeLeft = function () {
1571
+ _super.prototype.nudgeInternal.call(this, -1, 0);
1572
+ };
1573
+ /**
1574
+ * @override
1575
+ * @inheritDoc
1576
+ */
1577
+ Image.prototype.nudgeRight = function () {
1578
+ _super.prototype.nudgeInternal.call(this, +1, 0);
1579
+ };
1580
+ /**
1581
+ * @override
1582
+ * @inheritDoc
1583
+ */
1584
+ Image.prototype.setPosition = function (position) {
1585
+ if (this.canvas.getLayoutManager().isEnforcedPositioning) {
1586
+ if (position.top != undefined)
1587
+ this.fabricObject.set({ top: position.top });
1588
+ if (position.width != undefined) {
1589
+ this.layoutWidth = position.width;
1590
+ }
1591
+ if (position.height != undefined) {
1592
+ var premultipliedHeight = this.fabricObject.height;
1593
+ var newScale = position.height / premultipliedHeight;
1594
+ this.fabricObject.set({ scaleX: newScale, scaleY: newScale });
1595
+ this.setCoords();
1596
+ }
1597
+ if (position.left != undefined || position.width != undefined || position.height != undefined) {
1598
+ this.centerHorizontallyInLayoutWidth(position.left || 0);
1599
+ }
1600
+ }
1601
+ else {
1602
+ _super.prototype.setPosition.call(this, position);
1603
+ }
1604
+ };
1605
+ Image.prototype.centerHorizontallyInLayoutWidth = function (left) {
1606
+ var imageWidth = this.getBoundingBox().width;
1607
+ this.fabricObject.set({ left: left + (this.layoutWidth / 2) - (imageWidth / 2) });
1608
+ };
1609
+ Image.prototype.setCanvasImage = function (url) {
1610
+ return __awaiter(this, void 0, void 0, function () {
1611
+ var imageOptions, maxSizeScale, maxWidth;
1612
+ var _this = this;
1613
+ return __generator(this, function (_a) {
1614
+ switch (_a.label) {
1615
+ case 0:
1616
+ imageOptions = { crossOrigin: "anonymous" };
1617
+ maxSizeScale = 2;
1618
+ maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1619
+ return [4 /*yield*/, new Promise(function (resolve) {
1620
+ _this.fabricObject.setSrc(url, function (img) {
1621
+ var newScale = 1;
1622
+ var curWidth = newScale * img.width;
1623
+ if (curWidth > maxWidth) {
1624
+ newScale = maxWidth / curWidth;
1625
+ }
1626
+ img.set({
1627
+ scaleX: newScale,
1628
+ scaleY: newScale
1629
+ });
1630
+ img.setCoords();
1631
+ _this.redraw();
1632
+ resolve();
1633
+ }, imageOptions);
1634
+ })];
1635
+ case 1: return [2 /*return*/, _a.sent()];
1636
+ }
1637
+ });
1638
+ });
1639
+ };
1640
+ Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
1641
+ if (!minHeight) {
1642
+ return 0;
1643
+ }
1644
+ var premultipliedHeight = this.fabricObject.height;
1645
+ var newScale = minHeight / premultipliedHeight;
1646
+ return this.getBoundingBox().width * newScale;
1647
+ };
1648
+ Image.prototype.getMaxWidthBasedOnMaxHeight = function (maxHeight) {
1649
+ if (!maxHeight) {
1650
+ return Infinity;
1651
+ }
1652
+ var premultipliedHeight = this.fabricObject.height;
1653
+ var newScale = maxHeight / premultipliedHeight;
1654
+ return this.getBoundingBox().width * newScale;
1655
+ };
1656
+ return Image;
1657
+ }(AbstractCanvasObject));
1658
+
1659
+ var Rectangle = /** @class */ (function (_super) {
1660
+ __extends(Rectangle, _super);
1661
+ function Rectangle(canvas, fabricObject, persistedField) {
1662
+ var _this = _super.call(this, ObjectType.RECTANGLE, canvas, fabricObject, persistedField) || this;
1663
+ _this.canvas = canvas;
1664
+ return _this;
1665
+ }
1666
+ /**
1667
+ * @override
1668
+ * @inheritDoc
1669
+ */
1670
+ Rectangle.prototype.getColor = function () {
1671
+ return this.fabricObject.fill;
1672
+ };
1673
+ /**
1674
+ * @override
1675
+ * @inheritDoc
1676
+ */
1677
+ Rectangle.prototype.setColor = function (color) {
1678
+ this.fabricObject.set({ fill: color });
1679
+ this.data.color = color;
1680
+ this.redraw();
1681
+ };
1682
+ /**
1683
+ * @override
1684
+ * @inheritDoc
1685
+ */
1686
+ Rectangle.prototype.getStrokeColor = function () {
1687
+ return this.fabricObject.stroke;
1688
+ };
1689
+ /**
1690
+ * @override
1691
+ * @inheritDoc
1692
+ */
1693
+ Rectangle.prototype.setStrokeColor = function (color) {
1694
+ this.fabricObject.set({ stroke: color });
1695
+ this.data.color = color;
1696
+ this.redraw();
1697
+ };
1698
+ /**
1699
+ * @override
1700
+ * @inheritDoc
1701
+ */
1702
+ Rectangle.prototype.getStrokeWidth = function () {
1703
+ return this.fabricObject.strokeWidth;
1704
+ };
1705
+ /**
1706
+ * @override
1707
+ * @inheritDoc
1708
+ */
1709
+ Rectangle.prototype.setStrokeWidth = function (width) {
1710
+ this.fabricObject.set({ strokeWidth: width });
1711
+ this.data.strokeWidth = width;
1712
+ this.redraw();
1713
+ };
1714
+ /**
1715
+ * @override
1716
+ * @inheritDoc
1717
+ */
1718
+ Rectangle.prototype.centerHorizontally = function () {
1719
+ _super.prototype.centerHorizontallyInternal.call(this);
1720
+ };
1721
+ /**
1722
+ * @override
1723
+ * @inheritDoc
1724
+ */
1725
+ Rectangle.prototype.centerVertically = function () {
1726
+ _super.prototype.centerVerticallyInternal.call(this);
1727
+ };
1728
+ /**
1729
+ * @override
1730
+ * @inheritDoc
1731
+ */
1732
+ Rectangle.prototype.nudgeUp = function () {
1733
+ _super.prototype.nudgeInternal.call(this, 0, -1);
1734
+ };
1735
+ /**
1736
+ * @override
1737
+ * @inheritDoc
1738
+ */
1739
+ Rectangle.prototype.nudgeDown = function () {
1740
+ _super.prototype.nudgeInternal.call(this, 0, +1);
1741
+ };
1742
+ /**
1743
+ * @override
1744
+ * @inheritDoc
1745
+ */
1746
+ Rectangle.prototype.nudgeLeft = function () {
1747
+ _super.prototype.nudgeInternal.call(this, -1, 0);
1748
+ };
1749
+ /**
1750
+ * @override
1751
+ * @inheritDoc
1752
+ */
1753
+ Rectangle.prototype.nudgeRight = function () {
1754
+ _super.prototype.nudgeInternal.call(this, +1, 0);
1755
+ };
1756
+ /**
1757
+ * @override
1758
+ * @inheritDoc
1759
+ */
1760
+ Rectangle.prototype.afterScale = function (event) {
1761
+ this.updateDimensions();
1762
+ var _a = this.getDimensions(), width = _a.width, height = _a.height;
1763
+ this.fabricObject.set({ scaleX: 1, scaleY: 1, width: width.px, height: height.px });
1764
+ this.updateDimensions();
1765
+ };
1766
+ return Rectangle;
1767
+ }(AbstractCanvasObject));
1768
+
1769
+ var RichText = /** @class */ (function (_super) {
1770
+ __extends(RichText, _super);
1771
+ function RichText(canvas, fabricObject, persistedField) {
1772
+ var _this = _super.call(this, canvas, fabricObject, persistedField) || this;
1773
+ _this.data.type = ObjectType.RICH_TEXT;
1774
+ return _this;
1775
+ }
1776
+ Object.defineProperty(RichText.prototype, "htmlContent", {
1777
+ /**
1778
+ * @override
1779
+ * @inheritDoc
1780
+ */
1781
+ get: function () {
1782
+ return this.data.userText;
1783
+ },
1784
+ /**
1785
+ * @override
1786
+ * @inheritDoc
1787
+ */
1788
+ set: function (text) {
1789
+ this.data.userText = text;
1790
+ },
1791
+ enumerable: false,
1792
+ configurable: true
1793
+ });
1794
+ /**
1795
+ * @override
1796
+ * @inheritDoc
1797
+ */
1798
+ RichText.prototype.setRichTextContent = function (renderedContentUrl, htmlContent) {
1799
+ return __awaiter(this, void 0, void 0, function () {
1800
+ var canvasWidthPx;
1801
+ return __generator(this, function (_a) {
1802
+ switch (_a.label) {
1803
+ case 0:
1804
+ canvasWidthPx = this.canvas.getDimensions().widthPx;
1805
+ if (!renderedContentUrl)
1806
+ return [2 /*return*/];
1807
+ this.htmlContent = htmlContent;
1808
+ return [4 /*yield*/, this.setImageUrl(renderedContentUrl)];
1809
+ case 1:
1810
+ _a.sent();
1811
+ this.setImageWidth(canvasWidthPx);
1812
+ return [2 /*return*/];
1813
+ }
1814
+ });
1815
+ });
1816
+ };
1817
+ return RichText;
1818
+ }(Image));
1819
+
1820
+ var Text = /** @class */ (function (_super) {
1821
+ __extends(Text, _super);
1822
+ function Text(canvas, fabricObject, persistedField) {
1823
+ var _this_1 = _super.call(this, ObjectType.TEXT, canvas, fabricObject, persistedField) || this;
1824
+ _this_1.canvas = canvas;
1825
+ _this_1.fontLibrary = canvas.getFontLibrary();
1826
+ _this_1.baseComponentHeight = _this_1.fabricObject.height;
1827
+ _this_1.text$ = new BehaviorSubject(_this_1.fabricObject.text);
1828
+ _this_1.data.userText = _this_1.fabricObject.text;
1829
+ _this_1.textSelection$ = new BehaviorSubject(new TextSelection(_this_1.fabricObject, _this_1.fontLibrary));
1830
+ _this_1.fabricObject.set({ strokeWidth: 0 });
1831
+ _this_1.fabricObject.on("changed", function () { return _this_1.onTextChange(); });
1832
+ _this_1.fabricObject.on("selection:changed", function () { return _this_1.onSelectionChange(); });
1833
+ _this_1.applyBulletListMonkeyPatches();
1834
+ return _this_1;
1835
+ }
1836
+ /**
1837
+ * @override
1838
+ * @inheritDoc
1839
+ */
1840
+ Text.prototype.getText = function () {
1841
+ return this.text$.value;
1842
+ };
1843
+ /**
1844
+ * @override
1845
+ * @inheritDoc
1846
+ */
1847
+ Text.prototype.getText$ = function () {
1848
+ return this.text$;
1849
+ };
1850
+ /**
1851
+ * @override
1852
+ * @inheritDoc
1853
+ */
1854
+ Text.prototype.setText = function (text) {
1855
+ var style = this.fabricObject.getStyleAtPosition(0, true);
1856
+ this.fabricObject.set({ text: text });
1857
+ this.data.userText = this.fabricObject.text;
1858
+ this.text$.next(text);
1859
+ this.fabricObject.setSelectionStyles(style, 0, text.length);
1860
+ this.redraw();
1861
+ };
1862
+ /**
1863
+ * @override
1864
+ * @inheritDoc
1865
+ */
1866
+ Text.prototype.replaceText = function (target, replacement) {
1867
+ var start = this.getText().indexOf(target);
1868
+ this.fabricObject.insertChars(replacement, null, start, start + target.length);
1869
+ this.redraw();
1870
+ this.data.userText = this.fabricObject.text;
1871
+ this.text$.next(this.fabricObject.text);
1872
+ };
1873
+ /**
1874
+ * @override
1875
+ * @inheritDoc
1876
+ */
1877
+ Text.prototype.insertText = function (text, style, start, end) {
1878
+ this.fabricObject.insertChars(text, style, start, end);
1879
+ var newCursorLocation = start + text.length;
1880
+ this.fabricObject.selectionStart = newCursorLocation;
1881
+ this.fabricObject.selectionEnd = newCursorLocation;
1882
+ this.redraw();
1883
+ this.data.userText = this.fabricObject.text;
1884
+ this.text$.next(this.fabricObject.text);
1885
+ };
1886
+ /**
1887
+ * @override
1888
+ * @inheritDoc
1889
+ */
1890
+ Text.prototype.insertTextAtSelection = function (text, style) {
1891
+ var selection = this.getTextSelection();
1892
+ this.insertText(text, style, selection.start, selection.end);
1893
+ };
1894
+ /**
1895
+ * @override
1896
+ * @inheritDoc
1897
+ */
1898
+ Text.prototype.getColor = function () {
1899
+ return this.textSelection$.value.fill;
1900
+ };
1901
+ /**
1902
+ * @override
1903
+ * @inheritDoc
1904
+ */
1905
+ Text.prototype.setColor = function (color) {
1906
+ if (this.hasTextSelection()) {
1907
+ this.fabricObject.setSelectionStyles({ fill: color });
1908
+ }
1909
+ else {
1910
+ this.fabricObject.set({ fill: color });
1911
+ }
1912
+ this.data.color = color;
1913
+ this.updateTextSelection();
1914
+ this.redraw();
1915
+ };
1916
+ /**
1917
+ * @override
1918
+ * @inheritDoc
1919
+ */
1920
+ Text.prototype.getTextSelection = function () {
1921
+ return this.textSelection$.value;
1922
+ };
1923
+ /**
1924
+ * @override
1925
+ * @inheritDoc
1926
+ */
1927
+ Text.prototype.getTextSelection$ = function () {
1928
+ return this.textSelection$;
1929
+ };
1930
+ /**
1931
+ * @override
1932
+ * @inheritDoc
1933
+ */
1934
+ Text.prototype.setTextAlign = function (alignment) {
1935
+ this.fabricObject.set({ textAlign: alignment });
1936
+ this.redraw();
1937
+ this.updateTextSelection();
1938
+ };
1939
+ /**
1940
+ * @override
1941
+ * @inheritDoc
1942
+ */
1943
+ Text.prototype.setCharSpacing = function (spacing) {
1944
+ this.fabricObject.set({ charSpacing: spacing });
1945
+ this.redraw();
1946
+ this.updateTextSelection();
1947
+ };
1948
+ /**
1949
+ * @override
1950
+ * @inheritDoc
1951
+ */
1952
+ Text.prototype.setLineHeight = function (height) {
1953
+ this.fabricObject.set({ lineHeight: height });
1954
+ this.redraw();
1955
+ this.updateTextSelection();
1956
+ };
1957
+ /**
1958
+ * @override
1959
+ * @inheritDoc
1960
+ */
1961
+ Text.prototype.setBold = function (bold) {
1962
+ if (bold === void 0) { bold = true; }
1963
+ if (this.hasTextSelection()) {
1964
+ var start = this.textSelection$.value.start;
1965
+ for (var i = 0; i < this.textSelection$.value.length; i++) {
1966
+ var style = this.fabricObject.getStyleAtPosition(start + i, true);
1967
+ var font = this.fontLibrary.getFont(style.fontFamily);
1968
+ var fontWeight = bold ? font.boldWeight : font.normalWeight;
1969
+ this.fabricObject.setSelectionStyles({ fontWeight: fontWeight }, start + i, start + i + 1);
1970
+ }
1971
+ }
1972
+ else {
1973
+ var font = this.fontLibrary.getFont(this.fabricObject.fontFamily);
1974
+ var fontWeight = bold ? font.boldWeight : font.normalWeight;
1975
+ this.fabricObject.set({ fontWeight: fontWeight });
1976
+ }
1977
+ this.redraw();
1978
+ this.updateTextSelection();
1979
+ };
1980
+ /**
1981
+ * @override
1982
+ * @inheritDoc
1983
+ */
1984
+ Text.prototype.setBoldRegion = function (start, end, bold) {
1985
+ if (bold === void 0) { bold = true; }
1986
+ if (start > end)
1987
+ throw Error("Bad region specified: [" + start + " - " + end + "]");
1988
+ for (var i = start; i < end; i++) {
1989
+ var style = this.fabricObject.getStyleAtPosition(i, true);
1990
+ var font = this.fontLibrary.getFont(style.fontFamily);
1991
+ style.fontWeight = bold ? font.boldWeight : font.normalWeight;
1992
+ this.fabricObject.setSelectionStyles(style, i, i + 1);
1993
+ }
1994
+ this.redraw();
1995
+ };
1996
+ /**
1997
+ * @override
1998
+ * @inheritDoc
1999
+ */
2000
+ Text.prototype.setItalic = function (italic) {
2001
+ if (italic === void 0) { italic = true; }
2002
+ if (this.hasTextSelection()) {
2003
+ this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" });
2004
+ }
2005
+ else {
2006
+ this.fabricObject.set({ fontStyle: italic ? "italic" : "" });
2007
+ }
2008
+ this.redraw();
2009
+ this.updateTextSelection();
2010
+ };
2011
+ /**
2012
+ * @override
2013
+ * @inheritDoc
2014
+ */
2015
+ Text.prototype.setItalicRegion = function (start, end, italic) {
2016
+ if (italic === void 0) { italic = true; }
2017
+ if (start > end)
2018
+ throw Error("Bad region specified: [" + start + " - " + end + "]");
2019
+ this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" }, start, end);
2020
+ this.redraw();
2021
+ };
2022
+ /**
2023
+ * @override
2024
+ * @inheritDoc
2025
+ */
2026
+ Text.prototype.setStrikethrough = function (strikethrough) {
2027
+ if (strikethrough === void 0) { strikethrough = true; }
2028
+ if (this.hasTextSelection()) {
2029
+ this.fabricObject.setSelectionStyles({ linethrough: strikethrough });
2030
+ }
2031
+ else {
2032
+ this.fabricObject.set({ linethrough: strikethrough });
2033
+ }
2034
+ this.redraw();
2035
+ this.updateTextSelection();
2036
+ };
2037
+ /**
2038
+ * @override
2039
+ * @inheritDoc
2040
+ */
2041
+ Text.prototype.setUnderline = function (underline) {
2042
+ if (underline === void 0) { underline = true; }
2043
+ this.fabricObject.setSelectionStyles({ underline: underline });
2044
+ this.redraw();
2045
+ this.updateTextSelection();
2046
+ };
2047
+ /**
2048
+ * @override
2049
+ * @inheritDoc
2050
+ */
2051
+ Text.prototype.setFont = function (font) {
2052
+ if (this.hasTextSelection()) {
2053
+ this.fabricObject.setSelectionStyles({ fontFamily: font.family, fontWeight: font.normalWeight });
2054
+ }
2055
+ else {
2056
+ this.fabricObject.set({ fontFamily: font.family, fontWeight: font.normalWeight });
2057
+ }
2058
+ this.redraw();
2059
+ this.updateTextSelection();
2060
+ };
2061
+ /**
2062
+ * @override
2063
+ * @inheritDoc
2064
+ */
2065
+ Text.prototype.setFontSize = function (fontSize) {
2066
+ if (this.hasTextSelection()) {
2067
+ this.fabricObject.setSelectionStyles({ fontSize: fontSize });
2068
+ }
2069
+ else {
2070
+ this.fabricObject.set({ fontSize: fontSize });
2071
+ }
2072
+ this.redraw();
2073
+ this.updateTextSelection();
2074
+ };
2075
+ /**
2076
+ * @override
2077
+ * @inheritDoc
2078
+ */
2079
+ Text.prototype.setTextBackgroundColor = function (color) {
2080
+ if (this.hasTextSelection()) {
2081
+ this.fabricObject.setSelectionStyles({ textBackgroundColor: color });
2082
+ }
2083
+ else {
2084
+ this.fabricObject.set({ textBackgroundColor: color });
2085
+ }
2086
+ this.redraw();
2087
+ this.updateTextSelection();
2088
+ };
2089
+ /**
2090
+ * @override
2091
+ * @inheritDoc
2092
+ */
2093
+ Text.prototype.centerHorizontally = function () {
2094
+ _super.prototype.centerHorizontallyInternal.call(this);
2095
+ };
2096
+ /**
2097
+ * @override
2098
+ * @inheritDoc
2099
+ */
2100
+ Text.prototype.centerVertically = function () {
2101
+ _super.prototype.centerVerticallyInternal.call(this);
2102
+ };
2103
+ /**
2104
+ * @override
2105
+ * @inheritDoc
2106
+ */
2107
+ Text.prototype.nudgeUp = function () {
2108
+ _super.prototype.nudgeInternal.call(this, 0, -1);
2109
+ };
2110
+ /**
2111
+ * @override
2112
+ * @inheritDoc
2113
+ */
2114
+ Text.prototype.nudgeDown = function () {
2115
+ _super.prototype.nudgeInternal.call(this, 0, +1);
2116
+ };
2117
+ /**
2118
+ * @override
2119
+ * @inheritDoc
2120
+ */
2121
+ Text.prototype.nudgeLeft = function () {
2122
+ _super.prototype.nudgeInternal.call(this, -1, 0);
2123
+ };
2124
+ /**
2125
+ * @override
2126
+ * @inheritDoc
2127
+ */
2128
+ Text.prototype.nudgeRight = function () {
2129
+ _super.prototype.nudgeInternal.call(this, +1, 0);
2130
+ };
2131
+ /**
2132
+ * @override
2133
+ * @inheritDoc
2134
+ */
2135
+ Text.prototype.getBackgroundColor = function () {
2136
+ return this.fabricObject.backgroundColor;
2137
+ };
2138
+ /**
2139
+ * @override
2140
+ * @inheritDoc
2141
+ */
2142
+ Text.prototype.setBackgroundColor = function (color) {
2143
+ this.fabricObject.set({ backgroundColor: color });
2144
+ this.redraw();
2145
+ };
2146
+ /**
2147
+ * @override
2148
+ * @inheritDoc
2149
+ */
2150
+ Text.prototype.setPrefillType = function (prefillType) {
2151
+ this.data.prefillType = prefillType;
2152
+ };
2153
+ /**
2154
+ * @override
2155
+ * @inheritDoc
2156
+ */
2157
+ Text.prototype.getPrefillType = function () {
2158
+ return this.data.prefillType;
2159
+ };
2160
+ /**
2161
+ * @override
2162
+ * @inheritDoc
2163
+ */
2164
+ Text.prototype.getBulletMargin = function () {
2165
+ var _this_1 = this;
2166
+ if (!this.isBulleted())
2167
+ return 0;
2168
+ var fontSize = 0;
2169
+ each(this.fabricObject._textLines, function (textLine, lineIndex) {
2170
+ fontSize = Math.max(fontSize, _this_1.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
2171
+ });
2172
+ return fontSize * 0.6;
2173
+ };
2174
+ /**
2175
+ * @override
2176
+ * @inheritDoc
2177
+ */
2178
+ Text.prototype.getOrderedListMargin = function () {
2179
+ if (!this.isOrderedList())
2180
+ return 0;
2181
+ var orderedListMarkerEntities = this.fabricObject._orderedListMarkerEntities;
2182
+ var max = _(orderedListMarkerEntities)
2183
+ .filter(function (x) { return !!x; })
2184
+ .map(function (x) { return x.getBoundingRect(true, true).width; })
2185
+ .max();
2186
+ return (max * 1.2) || 0;
2187
+ };
2188
+ /**
2189
+ * @override
2190
+ * @inheritDoc
2191
+ */
2192
+ Text.prototype.isResizeCanvas = function () {
2193
+ return this.data.resizeCanvas;
2194
+ };
2195
+ /**
2196
+ * @override
2197
+ * @inheritDoc
2198
+ */
2199
+ Text.prototype.setResizeCanvas = function (value) {
2200
+ this.baseComponentHeight = this.fabricObject.height;
2201
+ this.data.resizeCanvas = value;
2202
+ };
2203
+ /**
2204
+ * @override
2205
+ * @inheritDoc
2206
+ */
2207
+ Text.prototype.focus = function () {
2208
+ this.fabricObject.hiddenTextarea.focus();
2209
+ };
2210
+ /**
2211
+ * @override
2212
+ * @inheritDoc
2213
+ */
2214
+ Text.prototype.isEditing = function () {
2215
+ return this.fabricObject.isEditing;
2216
+ };
2217
+ /**
2218
+ * @override
2219
+ * @inheritDoc
2220
+ */
2221
+ Text.prototype.enterEditing = function () {
2222
+ if (!this.isEditing()) {
2223
+ this.fabricObject.enterEditing();
2224
+ this.focus();
2225
+ this.selectAllText();
2226
+ this.redraw();
2227
+ }
2228
+ };
2229
+ /**
2230
+ * @override
2231
+ * @inheritDoc
2232
+ */
2233
+ Text.prototype.selectAllText = function () {
2234
+ this.fabricObject.selectAll();
2235
+ };
2236
+ /**
2237
+ * @override
2238
+ * @inheritDoc
2239
+ */
2240
+ Text.prototype.isBulleted = function () {
2241
+ return this.data.bulleted || false;
2242
+ };
2243
+ /**
2244
+ * @override
2245
+ * @inheritDoc
2246
+ */
2247
+ Text.prototype.enableBullets = function () {
2248
+ this.disableOrderedList();
2249
+ this.fabricObject["objectCaching"] = false;
2250
+ this.fabricObject["_bullets"] = this.fabricObject["_bullets"] || {};
2251
+ this.data.bulleted = true;
2252
+ this.notifyCanvasOfTextChanges();
2253
+ this.redraw();
2254
+ };
2255
+ /**
2256
+ * @override
2257
+ * @inheritDoc
2258
+ */
2259
+ Text.prototype.disableBullets = function () {
2260
+ this.removeBullets();
2261
+ this.data.bulleted = false;
2262
+ this.notifyCanvasOfTextChanges();
2263
+ this.redraw();
2264
+ };
2265
+ /**
2266
+ * @override
2267
+ * @inheritDoc
2268
+ */
2269
+ Text.prototype.isOrderedList = function () {
2270
+ return this.fabricObject._isOrderedList || false;
2271
+ };
2272
+ /**
2273
+ * @override
2274
+ * @inheritDoc
2275
+ */
2276
+ Text.prototype.enableOrderedList = function () {
2277
+ this.disableBullets();
2278
+ this.fabricObject.objectCaching = false;
2279
+ this.fabricObject._isOrderedList = true;
2280
+ this.notifyCanvasOfTextChanges();
2281
+ this.redraw();
2282
+ };
2283
+ /**
2284
+ * @override
2285
+ * @inheritDoc
2286
+ */
2287
+ Text.prototype.disableOrderedList = function () {
2288
+ this.removeOrderedListMarkers();
2289
+ delete this.fabricObject._isOrderedList;
2290
+ this.notifyCanvasOfTextChanges();
2291
+ this.redraw();
2292
+ };
2293
+ /**
2294
+ * @override
2295
+ * @inheritDoc
2296
+ */
2297
+ Text.prototype.setOrderedListStart = function (start) {
2298
+ this.fabricObject._orderedListStart = start;
2299
+ this.notifyCanvasOfTextChanges();
2300
+ this.redraw();
2301
+ };
2302
+ /**
2303
+ * @override
2304
+ * @inheritDoc
2305
+ */
2306
+ Text.prototype.getOrderedListStart = function () {
2307
+ return this.fabricObject._orderedListStart || 1;
2308
+ };
2309
+ Text.prototype.getSizeIncreaseSinceCreation = function () {
2310
+ return Math.max(0, this.fabricObject.height - this.baseComponentHeight);
2311
+ };
2312
+ Text.prototype.removeBullets = function () {
2313
+ var _this_1 = this;
2314
+ if (this.data.bulleted) {
2315
+ var bullets = this.fabricObject["_bullets"];
2316
+ delete this.fabricObject["_bullets"];
2317
+ each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2318
+ this.fabricObject["objectCaching"] = true;
2319
+ }
2320
+ };
2321
+ Text.prototype.removeOrderedListMarkers = function () {
2322
+ var _this_1 = this;
2323
+ if (this.fabricObject._isOrderedList) {
2324
+ var markerEntities = this.fabricObject._orderedListMarkerEntities;
2325
+ delete this.fabricObject._orderedListMarkerEntities;
2326
+ each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2327
+ this.fabricObject["objectCaching"] = true;
2328
+ }
2329
+ };
2330
+ Text.prototype.applyBulletListMonkeyPatches = function () {
2331
+ var _this = this;
2332
+ if (this.data.bulleted)
2333
+ this.enableBullets();
2334
+ if (this.fabricObject._isOrderedList)
2335
+ this.enableOrderedList();
2336
+ var originalRender = this.fabricObject["_render"];
2337
+ var fabric = this.canvas.fabric;
2338
+ this.fabricObject["_render"] = function (ctx) {
2339
+ var fabricText = this;
2340
+ if (fabricText["_bullets"]) {
2341
+ // Determine list of active bullets
2342
+ var currentBullets_1 = fabricText["_bullets"];
2343
+ var activeBullets_1 = {};
2344
+ each(fabricText._textLines, function (textLine, lineIndex) {
2345
+ if (textLine.length) {
2346
+ // Start of real lines will have offset 0 in styleMap
2347
+ var styleMap = fabricText._styleMap[lineIndex];
2348
+ if (styleMap.offset === 0) {
2349
+ if (currentBullets_1[lineIndex]) {
2350
+ // Reuse existing bullet for this line
2351
+ activeBullets_1[lineIndex] = currentBullets_1[lineIndex];
2352
+ }
2353
+ else {
2354
+ // Create new bullet for this line
2355
+ var options = {
2356
+ left: 0,
2357
+ top: 0,
2358
+ radius: 2,
2359
+ fill: fabricText.fill,
2360
+ scaleX: fabricText.scaleX,
2361
+ scaleY: fabricText.scaleY,
2362
+ strokeWidth: 0,
2363
+ lockMovementX: true,
2364
+ lockMovementY: true,
2365
+ hasControls: false,
2366
+ selectable: false,
2367
+ excludeFromJson: true
2368
+ };
2369
+ activeBullets_1[lineIndex] = new fabric.Circle(options);
2370
+ }
2371
+ }
2372
+ }
2373
+ });
2374
+ // Add/Remove bullets from canvas
2375
+ var canvas_1 = fabricText.canvas;
2376
+ var canvasDirty_1 = false;
2377
+ canvas_1.renderOnAddRemove = false;
2378
+ each(activeBullets_1, function (bullet) {
2379
+ if (!canvas_1.contains(bullet)) {
2380
+ canvas_1.add(bullet);
2381
+ canvasDirty_1 = true;
2382
+ }
2383
+ });
2384
+ each(currentBullets_1, function (bullet, key) {
2385
+ if (!activeBullets_1[key]) {
2386
+ canvas_1.remove(bullet);
2387
+ canvasDirty_1 = true;
2388
+ }
2389
+ });
2390
+ canvas_1.renderOnAddRemove = true;
2391
+ fabricText["_bullets"] = activeBullets_1;
2392
+ if (canvasDirty_1) {
2393
+ // Fabric doesn't like it when you add new things within render so use a sneaky timeout to delay render
2394
+ setTimeout(canvas_1.renderAll.bind(canvas_1));
2395
+ }
2396
+ }
2397
+ if (fabricText._isOrderedList) {
2398
+ var existingMarkers_1 = fabricText._orderedListMarkerEntities || [];
2399
+ var activeMarkers_1 = [];
2400
+ each(fabricText._textLines, function (textLine, lineIndex) {
2401
+ if (textLine.length) {
2402
+ // Start of real lines will have offset 0 in styleMap
2403
+ var styleMap = fabricText._styleMap[lineIndex];
2404
+ if (styleMap.offset === 0) {
2405
+ if (existingMarkers_1[lineIndex]) {
2406
+ // Reuse existing marker for this line
2407
+ activeMarkers_1[lineIndex] = existingMarkers_1[lineIndex];
2408
+ }
2409
+ else {
2410
+ // Create new marker for this line
2411
+ var textbox = new fabric.Textbox(lineIndex + ".", {
2412
+ left: 0,
2413
+ top: 0,
2414
+ fill: fabricText.fill,
2415
+ scaleX: fabricText.scaleX,
2416
+ scaleY: fabricText.scaleY,
2417
+ strokeWidth: 0,
2418
+ lockMovementX: true,
2419
+ lockMovementY: true,
2420
+ hasControls: false,
2421
+ selectable: false
2422
+ });
2423
+ textbox._isSlaveObject = true;
2424
+ activeMarkers_1[lineIndex] = textbox;
2425
+ }
2426
+ }
2427
+ }
2428
+ });
2429
+ // Add/Remove markers from canvas
2430
+ var canvas_2 = fabricText.canvas;
2431
+ var canvasDirty_2 = false;
2432
+ canvas_2.renderOnAddRemove = false;
2433
+ each(activeMarkers_1, function (marker) {
2434
+ if (!marker)
2435
+ return;
2436
+ if (!canvas_2.contains(marker)) {
2437
+ canvas_2.add(marker);
2438
+ canvasDirty_2 = true;
2439
+ }
2440
+ });
2441
+ each(existingMarkers_1, function (marker, key) {
2442
+ if (!marker)
2443
+ return;
2444
+ if (!activeMarkers_1[key]) {
2445
+ canvas_2.remove(marker);
2446
+ canvasDirty_2 = true;
2447
+ }
2448
+ });
2449
+ canvas_2.renderOnAddRemove = true;
2450
+ fabricText._orderedListMarkerEntities = activeMarkers_1;
2451
+ if (canvasDirty_2) {
2452
+ // Fabric doesn't like it when you add new things within render so use a sneaky timeout to delay render
2453
+ setTimeout(canvas_2.renderAll.bind(canvas_2));
2454
+ }
2455
+ }
2456
+ originalRender.apply(fabricText, [ctx]);
2457
+ };
2458
+ var originalRenderTextLine = this.fabricObject["_renderTextLine"];
2459
+ this.fabricObject["_renderTextLine"] = function (method, ctx, line, left, top, lineIndex) {
2460
+ var fabricText = this;
2461
+ var bullets = fabricText._bullets;
2462
+ if (bullets && bullets[lineIndex]) {
2463
+ var bullet = bullets[lineIndex];
2464
+ var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
2465
+ var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
2466
+ var radius = fontSize / 5;
2467
+ var angle = fabricText.angle;
2468
+ var theta = angle * Math.PI / 180;
2469
+ var x = -radius * 2;
2470
+ var y = (fabricText.height / 2) + top - (fontSize / 1.5);
2471
+ var xOffset = (x * Math.cos(theta)) - (y * Math.sin(theta));
2472
+ var yOffset = (x * Math.sin(theta)) + (y * Math.cos(theta));
2473
+ var bulletCenterOffset = [-radius * Math.sqrt(2) / 2, -radius * Math.sqrt(2) / 2];
2474
+ bullet.set({
2475
+ radius: radius,
2476
+ fill: color,
2477
+ left: fabricText.left + xOffset + bulletCenterOffset[0],
2478
+ top: fabricText.top + yOffset + bulletCenterOffset[1]
2479
+ });
2480
+ }
2481
+ var orderedListMarkerEntities = fabricText._orderedListMarkerEntities;
2482
+ var xShift = -_this.getOrderedListMargin() + 1;
2483
+ if (orderedListMarkerEntities && orderedListMarkerEntities[lineIndex]) {
2484
+ var entry = orderedListMarkerEntities[lineIndex];
2485
+ var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
2486
+ var fontFamily = this.getValueOfPropertyAt(lineIndex, 0, "fontFamily");
2487
+ var fontWeight = this.getValueOfPropertyAt(lineIndex, 0, "fontWeight");
2488
+ var fontStyle = this.getValueOfPropertyAt(lineIndex, 0, "fontStyle");
2489
+ var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
2490
+ var angle = fabricText.angle;
2491
+ var theta = angle * Math.PI / 180;
2492
+ var yShift = (fabricText.height / 2) + top - fontSize - 1;
2493
+ var xOffset = (xShift * Math.cos(theta)) - (yShift * Math.sin(theta));
2494
+ var yOffset = (xShift * Math.sin(theta)) + (yShift * Math.cos(theta));
2495
+ var lineNumber = _this.getOrderedListStart();
2496
+ for (var i = 0; i < lineIndex; i++) {
2497
+ if (orderedListMarkerEntities[i])
2498
+ lineNumber++;
2499
+ }
2500
+ entry.set({
2501
+ width: 1,
2502
+ fontSize: fontSize,
2503
+ fontFamily: fontFamily,
2504
+ fontWeight: fontWeight,
2505
+ fontStyle: fontStyle,
2506
+ fill: color,
2507
+ left: fabricText.left + xOffset,
2508
+ top: fabricText.top + yOffset,
2509
+ angle: fabricText.angle,
2510
+ text: lineNumber + "."
2511
+ });
2512
+ }
2513
+ originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
2514
+ };
2515
+ };
2516
+ /**
2517
+ * @override
2518
+ * @inheritDoc
2519
+ */
2520
+ Text.prototype.updateFabricObjectBehavior = function () {
2521
+ _super.prototype.updateFabricObjectBehavior.call(this);
2522
+ var profile = this.canvas.getProfile();
2523
+ var allowManualPositioning = !this.canvas.getLayoutManager().isEnforcedPositioning;
2524
+ this.fabricObject.set({
2525
+ lockScalingY: true,
2526
+ lockScalingX: this.isPinToBottom(),
2527
+ lockScalingFlip: true
2528
+ });
2529
+ this.fabricObject.setControlsVisibility({
2530
+ tl: false,
2531
+ tr: false,
2532
+ br: false,
2533
+ bl: false,
2534
+ ml: allowManualPositioning && profile.allowScale && !this.isPinToBottom(),
2535
+ mt: false,
2536
+ mr: allowManualPositioning && profile.allowScale && !this.isPinToBottom(),
2537
+ mb: false
2538
+ });
2539
+ this.redraw();
2540
+ };
2541
+ Text.prototype.onTextChange = function () {
2542
+ this.data.userText = this.fabricObject.text;
2543
+ this.text$.next(this.fabricObject.text);
2544
+ if (this.getBoundingBox().width > this.canvas.getDimensions().widthPx) {
2545
+ this.fabricObject.set({ left: 0, width: this.canvas.getDimensions().widthPx });
2546
+ this.redraw();
2547
+ }
2548
+ };
2549
+ Text.prototype.onDelete = function () {
2550
+ this.removeBullets();
2551
+ };
2552
+ Text.prototype.onSelectionChange = function () {
2553
+ this.updateTextSelection();
2554
+ };
2555
+ Text.prototype.hasTextSelection = function () {
2556
+ return this.canvas.getSelection().isText && this.textSelection$.value.length > 0;
2557
+ };
2558
+ Text.prototype.updateTextSelection = function () {
2559
+ if (this.canvas.headless)
2560
+ return;
2561
+ this.textSelection$.next(new TextSelection(this.fabricObject, this.fontLibrary));
2562
+ this.notifyCanvasOfTextChanges();
2563
+ };
2564
+ Text.prototype.notifyCanvasOfTextChanges = function () {
2565
+ this.canvas.notifyTextChanged();
2566
+ };
2567
+ return Text;
2568
+ }(AbstractCanvasObject));
2569
+ var TextSelection = /** @class */ (function () {
2570
+ function TextSelection(fabricObject, fontLibrary) {
2571
+ this.fabricObject = fabricObject;
2572
+ this.fontLibrary = fontLibrary;
2573
+ this.start = this.fabricObject.selectionStart;
2574
+ this.end = this.fabricObject.selectionEnd;
2575
+ this.length = this.end - this.start;
2576
+ var cursorLoc = this.fabricObject.get2DCursorLocation();
2577
+ this.lineIndex = cursorLoc.lineIndex;
2578
+ this.charIndex = cursorLoc.charIndex;
2579
+ var style = this.fabricObject.getCompleteStyleDeclaration(this.lineIndex, this.charIndex);
2580
+ var hasSelection = this.length > 0;
2581
+ this.font = hasSelection ? this.fontLibrary.getFont(style.fontFamily) : this.fontLibrary.getFont(this.fabricObject.fontFamily);
2582
+ this.fontSize = hasSelection ? style.fontSize : this.fabricObject.fontSize;
2583
+ this.fontWeight = hasSelection ? style.fontWeight : this.fabricObject.fontWeight;
2584
+ this.bold = this.font.isBold(this.fontWeight);
2585
+ this.italic = hasSelection ? style.fontStyle === "italic" : this.fabricObject.fontStyle === "italic";
2586
+ this.underline = hasSelection ? style.underline : this.fabricObject.underline;
2587
+ this.strikethrough = hasSelection ? style.linethrough : this.fabricObject.linethrough;
2588
+ this.overline = hasSelection ? style.overline : this.fabricObject.overline;
2589
+ this.textBackgroundColor = hasSelection ? style.textBackgroundColor : this.fabricObject.textBackgroundColor;
2590
+ this.textAlign = this.fabricObject.textAlign;
2591
+ this.charSpacing = this.fabricObject.charSpacing;
2592
+ this.lineHeight = this.fabricObject.lineHeight;
2593
+ this.fill = style.fill;
2594
+ this.stroke = style.stroke;
2595
+ this.strokeWidth = style.strokeWidth;
2596
+ }
2597
+ return TextSelection;
2598
+ }());
2599
+
2600
+ var VerticalRule = /** @class */ (function (_super) {
2601
+ __extends(VerticalRule, _super);
2602
+ function VerticalRule(canvas, fabricObject, persistedField) {
2603
+ var _this = _super.call(this, ObjectType.VERTICAL_RULE, canvas, fabricObject, persistedField) || this;
2604
+ _this.strokeWidth$ = new BehaviorSubject(2);
2605
+ _this.canvas = canvas;
2606
+ _this.strokeWidth$.next(_this.getDimensions().width.px);
2607
+ _this.fabricObject.set({ strokeWidth: 0 });
2608
+ return _this;
2609
+ }
2610
+ /**
2611
+ * @override
2612
+ * @inheritDoc
2613
+ */
2614
+ VerticalRule.prototype.getStrokeWidth = function () {
2615
+ return this.fabricObject.width;
2616
+ };
2617
+ /**
2618
+ * @override
2619
+ * @inheritDoc
2620
+ */
2621
+ VerticalRule.prototype.getStrokeWidth$ = function () {
2622
+ return this.strokeWidth$;
2623
+ };
2624
+ /**
2625
+ * @override
2626
+ * @inheritDoc
2627
+ */
2628
+ VerticalRule.prototype.setStrokeWidth = function (width) {
2629
+ this.strokeWidth$.next(width);
2630
+ this.data.strokeWidth = width;
2631
+ this.setPosition({ width: width });
2632
+ this.canvas.notifyObjectListChanged();
2633
+ this.redraw();
2634
+ };
2635
+ /**
2636
+ * @override
2637
+ * @inheritDoc
2638
+ */
2639
+ VerticalRule.prototype.getColor = function () {
2640
+ return this.fabricObject.fill;
2641
+ };
2642
+ /**
2643
+ * @override
2644
+ * @inheritDoc
2645
+ */
2646
+ VerticalRule.prototype.setColor = function (color) {
2647
+ this.fabricObject.set({ fill: color, stroke: color });
2648
+ this.data.color = color;
2649
+ this.redraw();
2650
+ };
2651
+ /**
2652
+ * @override
2653
+ * @inheritDoc
2654
+ */
2655
+ VerticalRule.prototype.centerHorizontally = function () {
2656
+ _super.prototype.centerHorizontallyInternal.call(this);
2657
+ };
2658
+ /**
2659
+ * @override
2660
+ * @inheritDoc
2661
+ */
2662
+ VerticalRule.prototype.centerVertically = function () {
2663
+ _super.prototype.centerVerticallyInternal.call(this);
2664
+ };
2665
+ /**
2666
+ * @override
2667
+ * @inheritDoc
2668
+ */
2669
+ VerticalRule.prototype.nudgeUp = function () {
2670
+ _super.prototype.nudgeInternal.call(this, 0, -1);
2671
+ };
2672
+ /**
2673
+ * @override
2674
+ * @inheritDoc
2675
+ */
2676
+ VerticalRule.prototype.nudgeDown = function () {
2677
+ _super.prototype.nudgeInternal.call(this, 0, +1);
2678
+ };
2679
+ /**
2680
+ * @override
2681
+ * @inheritDoc
2682
+ */
2683
+ VerticalRule.prototype.nudgeLeft = function () {
2684
+ _super.prototype.nudgeInternal.call(this, -1, 0);
2685
+ };
2686
+ /**
2687
+ * @override
2688
+ * @inheritDoc
2689
+ */
2690
+ VerticalRule.prototype.nudgeRight = function () {
2691
+ _super.prototype.nudgeInternal.call(this, +1, 0);
2692
+ };
2693
+ return VerticalRule;
2694
+ }(AbstractCanvasObject));
2695
+
2696
+ /**
2697
+ * Profile with as many features disabled as possible.
2698
+ */
2699
+ var DefaultCanvasProfile = /** @class */ (function () {
2700
+ function DefaultCanvasProfile() {
2701
+ this.allowMultiSelect = false;
2702
+ this.enterTextEditImmediatelyOnSelect = true;
2703
+ this.allowObjectsToLeaveCanvas = false;
2704
+ this.allowMove = false;
2705
+ this.allowRotate = false;
2706
+ this.allowScale = false;
2707
+ this.defaultFont = "Lato";
2708
+ this.defaultFontSize = 9;
2709
+ this.defaultFontColor = "#000000";
2710
+ this.defaultLineHeight = 1.8;
2711
+ this.defaultCharacterSpacing = 0;
2712
+ this.defaultTextAlignment = "left";
2713
+ this.defaultBorderColor = "#000000";
2714
+ this.defaultBorderWidth = 1;
2715
+ this.defaultCutoffColor = "#000000";
2716
+ this.defaultCutoffWidth = 1;
2717
+ }
2718
+ return DefaultCanvasProfile;
2719
+ }());
2720
+
2721
+ var ImageType;
2722
+ (function (ImageType) {
2723
+ ImageType["DEFAULT"] = "DEFAULT";
2724
+ ImageType["BACKGROUND"] = "BACKGROUND";
2725
+ ImageType["LOGO"] = "LOGO";
2726
+ ImageType["PHOTO"] = "PHOTO";
2727
+ })(ImageType || (ImageType = {}));
2728
+
2729
+ var ObjectType;
2730
+ (function (ObjectType) {
2731
+ ObjectType["TEXT"] = "TEXT";
2732
+ ObjectType["BORDER"] = "BORDER";
2733
+ ObjectType["IMAGE"] = "IMAGE";
2734
+ ObjectType["RECTANGLE"] = "RECTANGLE";
2735
+ ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
2736
+ ObjectType["CUTOFF"] = "CUTOFF";
2737
+ ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
2738
+ ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
2739
+ ObjectType["RICH_TEXT"] = "RICH_TEXT";
2740
+ ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
2741
+ })(ObjectType || (ObjectType = {}));
2742
+
2743
+ var AbstractInteractiveCanvas = /** @class */ (function () {
2744
+ function AbstractInteractiveCanvas(fabric, fabricCanvas, devicePixelRatio) {
2745
+ this.fabric = fabric;
2746
+ this.fabricCanvas = fabricCanvas;
2747
+ this.devicePixelRatio = devicePixelRatio;
2748
+ this.fontLibrary = new FontLibrary();
2749
+ this.dimensionChangeRejections$ = new Subject();
2750
+ this.IMAGE_CAPTURE_COEFFICIENT = this.calculateImageCaptureCoefficient();
2751
+ /**
2752
+ * Fabric defaults to only 2 decimal places when saving, which causes havoc on the scaling of large images.
2753
+ */
2754
+ fabric.Object.NUM_FRACTION_DIGITS = 10;
2755
+ this.baseDimensions = new PixelCanvasDimensions(this.fabricCanvas.width, this.fabricCanvas.height);
2756
+ var baseRestrictions = { width: { min: 1 }, height: { min: 1 } };
2757
+ //Initialize properties
2758
+ this.dimensions$ = new BehaviorSubject(this.baseDimensions);
2759
+ this.dimensionRestrictions$ = new BehaviorSubject(baseRestrictions);
2760
+ this.zoom$ = new BehaviorSubject(1);
2761
+ this.profile$ = new BehaviorSubject(new DefaultCanvasProfile());
2762
+ this.layoutManager$ = new BehaviorSubject(new AdvancedLayoutManager(this));
2763
+ this.backgroundColor$ = new BehaviorSubject(this.fabricCanvas.backgroundColor);
2764
+ this.objects$ = new BehaviorSubject([]);
2765
+ this.selection$ = new BehaviorSubject(new SelectionData([]));
2766
+ //Configure canvas behaviour
2767
+ this.fabricCanvas.stateful = true;
2768
+ this.fabricCanvas.preserveObjectStacking = true;
2769
+ this.fabricCanvas.perPixelTargetFind = true;
2770
+ this.fabricCanvas.targetFindTolerance = 10;
2771
+ this.setBackgroundColor("#FFFFFF");
2772
+ }
2773
+ /**
2774
+ * @override
2775
+ * @inheritDoc
2776
+ */
2777
+ AbstractInteractiveCanvas.prototype.getFontLibrary = function () {
2778
+ return this.fontLibrary;
2779
+ };
2780
+ /**
2781
+ * @override
2782
+ * @inheritDoc
2783
+ */
2784
+ AbstractInteractiveCanvas.prototype.getProfile = function () {
2785
+ return this.profile$.value;
2786
+ };
2787
+ /**
2788
+ * @override
2789
+ * @inheritDoc
2790
+ */
2791
+ AbstractInteractiveCanvas.prototype.getProfile$ = function () {
2792
+ return this.profile$;
2793
+ };
2794
+ /**
2795
+ * @override
2796
+ * @inheritDoc
2797
+ */
2798
+ AbstractInteractiveCanvas.prototype.setProfile = function (profile) {
2799
+ this.profile$.next(profile);
2800
+ this.onProfileChanged(profile);
2801
+ this.redraw();
2802
+ };
2803
+ /**
2804
+ * @override
2805
+ * @inheritDoc
2806
+ */
2807
+ AbstractInteractiveCanvas.prototype.getLayoutManager = function () {
2808
+ return this.layoutManager$.value;
2809
+ };
2810
+ /**
2811
+ * @override
2812
+ * @inheritDoc
2813
+ */
2814
+ AbstractInteractiveCanvas.prototype.getLayoutManager$ = function () {
2815
+ return this.layoutManager$;
2816
+ };
2817
+ /**
2818
+ * @override
2819
+ * @inheritDoc
2820
+ */
2821
+ AbstractInteractiveCanvas.prototype.setLayoutManager = function (layoutManager) {
2822
+ if (layoutManager === LayoutManager.STANDARD) {
2823
+ this.layoutManager$.next(new StandardLayoutManager(this));
2824
+ }
2825
+ else {
2826
+ this.layoutManager$.next(new AdvancedLayoutManager(this));
2827
+ }
2828
+ this.layoutManager$.value.onInit();
2829
+ };
2830
+ /**
2831
+ * @override
2832
+ * @inheritDoc
2833
+ */
2834
+ AbstractInteractiveCanvas.prototype.getBackgroundColor = function () {
2835
+ return this.backgroundColor$.value;
2836
+ };
2837
+ /**
2838
+ * @override
2839
+ * @inheritDoc
2840
+ */
2841
+ AbstractInteractiveCanvas.prototype.getBackgroundColor$ = function () {
2842
+ return this.backgroundColor$;
2843
+ };
2844
+ /**
2845
+ * @override
2846
+ * @inheritDoc
2847
+ */
2848
+ AbstractInteractiveCanvas.prototype.setBackgroundColor = function (color) {
2849
+ if (color === void 0) { color = "White"; }
2850
+ this.fabricCanvas.setBackgroundColor(color, function () {
2851
+ });
2852
+ this.fabricCanvas.renderAll();
2853
+ this.backgroundColor$.next(color);
2854
+ };
2855
+ /**
2856
+ * @override
2857
+ * @inheritDoc
2858
+ */
2859
+ AbstractInteractiveCanvas.prototype.getDimensions = function () {
2860
+ return this.dimensions$.value;
2861
+ };
2862
+ /**
2863
+ * @override
2864
+ * @inheritDoc
2865
+ */
2866
+ AbstractInteractiveCanvas.prototype.getBaseDimensions = function () {
2867
+ return this.baseDimensions;
2868
+ };
2869
+ /**
2870
+ * @override
2871
+ * @inheritDoc
2872
+ */
2873
+ AbstractInteractiveCanvas.prototype.getDimensions$ = function () {
2874
+ return this.dimensions$;
2875
+ };
2876
+ /**
2877
+ * @override
2878
+ * @inheritDoc
2879
+ */
2880
+ AbstractInteractiveCanvas.prototype.setDimensions = function (dimensions) {
2881
+ if (this.dimensionsExceedRestrictions(dimensions)) {
2882
+ console.info("Requested canvas dimensions exceed current restrictions", dimensions, this.dimensionRestrictions$.value);
2883
+ this.dimensionChangeRejections$.next(dimensions);
2884
+ return;
2885
+ }
2886
+ this.updateCanvasDimensions(dimensions, this.zoom$.value);
2887
+ this.dimensions$.next(dimensions);
2888
+ this.onDimensionsChange();
2889
+ };
2890
+ /**
2891
+ * @override
2892
+ * @inheritDoc
2893
+ */
2894
+ AbstractInteractiveCanvas.prototype.setBaseDimensions = function (dimensions) {
2895
+ this.baseDimensions = dimensions;
2896
+ this.setDimensions(dimensions);
2897
+ };
2898
+ /**
2899
+ * @override
2900
+ * @inheritDoc
2901
+ */
2902
+ AbstractInteractiveCanvas.prototype.getDimensionChangeRejections$ = function () {
2903
+ return this.dimensionChangeRejections$;
2904
+ };
2905
+ /**
2906
+ * @override
2907
+ * @inheritDoc
2908
+ */
2909
+ AbstractInteractiveCanvas.prototype.getDimensionsRestrictions = function () {
2910
+ return this.dimensionRestrictions$.value;
2911
+ };
2912
+ /**
2913
+ * @override
2914
+ * @inheritDoc
2915
+ */
2916
+ AbstractInteractiveCanvas.prototype.getDimensionsRestrictions$ = function () {
2917
+ return this.dimensionRestrictions$;
2918
+ };
2919
+ /**
2920
+ * @override
2921
+ * @inheritDoc
2922
+ */
2923
+ AbstractInteractiveCanvas.prototype.setDimensionRestrictions = function (restrictions) {
2924
+ this.dimensionRestrictions$.next(restrictions);
2925
+ var dimensions = this.getDimensions();
2926
+ if (this.dimensionsExceedRestrictions(dimensions)) {
2927
+ 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))));
2929
+ this.setBaseDimensions(newDimensions);
2930
+ }
2931
+ };
2932
+ AbstractInteractiveCanvas.prototype.getMargin = function () {
2933
+ var borderWidth = this.getObjectsByTypeInternal(ObjectType.BORDER)
2934
+ .map(function (border) { return border.getStrokeWidth(); })
2935
+ .reduce(function (current, next) { return Math.max(current, next); }, 0);
2936
+ var borderPadding = this.getObjectsByTypeInternal(ObjectType.BORDER)
2937
+ .map(function (border) { return border.getPadding(); })
2938
+ .reduce(function (current, next) {
2939
+ return {
2940
+ top: Math.max(current.top, next.top),
2941
+ right: Math.max(current.right, next.right),
2942
+ bottom: Math.max(current.bottom, next.bottom),
2943
+ left: Math.max(current.left, next.left)
2944
+ };
2945
+ }, { top: 0, right: 0, bottom: 0, left: 0 });
2946
+ var cutoffWidth = this.getObjectsByTypeInternal(ObjectType.CUTOFF)
2947
+ .map(function (border) { return border.getStrokeWidth(); })
2948
+ .reduce(function (current, next) { return Math.max(current, next); }, 0);
2949
+ // noinspection JSSuspiciousNameCombination
2950
+ return {
2951
+ top: borderWidth + borderPadding.top,
2952
+ right: borderWidth + borderPadding.right,
2953
+ bottom: Math.max(cutoffWidth, borderWidth) + borderPadding.bottom,
2954
+ left: borderWidth + borderPadding.left
2955
+ };
2956
+ };
2957
+ /**
2958
+ * @override
2959
+ * @inheritDoc
2960
+ */
2961
+ AbstractInteractiveCanvas.prototype.getZoom = function () {
2962
+ return this.zoom$.value;
2963
+ };
2964
+ /**
2965
+ * @override
2966
+ * @inheritDoc
2967
+ */
2968
+ AbstractInteractiveCanvas.prototype.getZoom$ = function () {
2969
+ return this.zoom$;
2970
+ };
2971
+ /**
2972
+ * @override
2973
+ * @inheritDoc
2974
+ */
2975
+ AbstractInteractiveCanvas.prototype.setZoom = function (zoom) {
2976
+ this.updateCanvasDimensions(this.dimensions$.value, zoom);
2977
+ this.zoom$.next(zoom);
2978
+ };
2979
+ /**
2980
+ * @override
2981
+ * @inheritDoc
2982
+ */
2983
+ AbstractInteractiveCanvas.prototype.getObjects = function () {
2984
+ return this.objects$.value;
2985
+ };
2986
+ /**
2987
+ * Get the list of objects directly.
2988
+ */
2989
+ AbstractInteractiveCanvas.prototype.getObjectsInternal = function () {
2990
+ return this.objects$.value;
2991
+ };
2992
+ /**
2993
+ * @override
2994
+ * @inheritDoc
2995
+ */
2996
+ AbstractInteractiveCanvas.prototype.getObjectsByTypeInternal = function (type) {
2997
+ return _(this.getObjectsInternal())
2998
+ .filter(function (object) { return object.getType() === type; })
2999
+ .value();
3000
+ };
3001
+ /**
3002
+ * @override
3003
+ * @inheritDoc
3004
+ */
3005
+ AbstractInteractiveCanvas.prototype.getObjectsByTypesInternal = function () {
3006
+ var types = [];
3007
+ for (var _i = 0; _i < arguments.length; _i++) {
3008
+ types[_i] = arguments[_i];
3009
+ }
3010
+ return _(this.getObjectsInternal())
3011
+ .filter(function (object) { return _(types).includes(object.getType()); })
3012
+ .value();
3013
+ };
3014
+ /**
3015
+ * @override
3016
+ * @inheritDoc
3017
+ */
3018
+ AbstractInteractiveCanvas.prototype.getObjects$ = function () {
3019
+ return this.objects$;
3020
+ };
3021
+ /**
3022
+ * @override
3023
+ * @inheritDoc
3024
+ */
3025
+ AbstractInteractiveCanvas.prototype.removeObject = function (target) {
3026
+ var concreteObject = this.findFabricObject(target.getId());
3027
+ this.fabricCanvas.remove(concreteObject);
3028
+ this.objects$.next(_(this.objects$.value)
3029
+ .filter(function (object) { return object.getId() !== target.getId(); })
3030
+ .value());
3031
+ this.onObjectListChange();
3032
+ };
3033
+ /**
3034
+ * @override
3035
+ * @inheritDoc
3036
+ */
3037
+ AbstractInteractiveCanvas.prototype.addImageObject = function (imageUrl) {
3038
+ return __awaiter(this, void 0, void 0, function () {
3039
+ var maxSizeScale, maxWidth, options;
3040
+ var _this = this;
3041
+ return __generator(this, function (_a) {
3042
+ switch (_a.label) {
3043
+ case 0:
3044
+ maxSizeScale = 2;
3045
+ maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
3046
+ options = { crossOrigin: "anonymous" };
3047
+ return [4 /*yield*/, new Promise(function (resolve) {
3048
+ _this.fabric.Image.fromURL(imageUrl, function (fabricImage) {
3049
+ var id = _this.randomId();
3050
+ var newScale = 1;
3051
+ var curWidth = newScale * fabricImage.width;
3052
+ if (curWidth > maxWidth) {
3053
+ newScale = maxWidth / curWidth;
3054
+ }
3055
+ fabricImage.set({
3056
+ id: id,
3057
+ scaleX: newScale,
3058
+ scaleY: newScale
3059
+ });
3060
+ _this.fabricCanvas.add(fabricImage);
3061
+ var object = new Image(_this, fabricImage);
3062
+ _this.trackNewObject(object);
3063
+ _this.selectFabricObject(fabricImage);
3064
+ _this.syncObjectList();
3065
+ resolve(object);
3066
+ }, options);
3067
+ })];
3068
+ case 1: return [2 /*return*/, _a.sent()];
3069
+ }
3070
+ });
3071
+ });
3072
+ };
3073
+ /**
3074
+ * @override
3075
+ * @inheritDoc
3076
+ */
3077
+ AbstractInteractiveCanvas.prototype.addTextObject = function () {
3078
+ return __awaiter(this, void 0, void 0, function () {
3079
+ var profile, id, fontSizePx, canvasWidthPx, lowestTextPointPx, topPx, textOptions, fabricTextbox, object;
3080
+ return __generator(this, function (_a) {
3081
+ profile = this.profile$.value;
3082
+ id = this.randomId();
3083
+ fontSizePx = profile.defaultFontSize;
3084
+ canvasWidthPx = this.getDimensions().widthPx;
3085
+ lowestTextPointPx = this.getLowestTextPoint();
3086
+ topPx = Math.min(lowestTextPointPx, this.getDimensions().heightPx - fontSizePx);
3087
+ textOptions = {
3088
+ id: id,
3089
+ top: topPx,
3090
+ left: 5,
3091
+ width: canvasWidthPx - 10,
3092
+ fill: profile.defaultFontColor,
3093
+ fontSize: fontSizePx,
3094
+ fontFamily: profile.defaultFont,
3095
+ textAlign: profile.defaultTextAlignment,
3096
+ multiLine: true,
3097
+ lineHeight: profile.defaultLineHeight,
3098
+ charSpacing: profile.defaultCharacterSpacing
3099
+ };
3100
+ fabricTextbox = new this.fabric.Textbox("Text goes here", textOptions);
3101
+ this.fabricCanvas.add(fabricTextbox);
3102
+ object = new Text(this, fabricTextbox);
3103
+ this.trackNewObject(object);
3104
+ this.selectFabricObject(fabricTextbox);
3105
+ this.syncObjectList();
3106
+ return [2 /*return*/, object];
3107
+ });
3108
+ });
3109
+ };
3110
+ /**
3111
+ * @override
3112
+ * @inheritDoc
3113
+ */
3114
+ AbstractInteractiveCanvas.prototype.addRichTextObject = function (imageUrl, htmlContent) {
3115
+ return __awaiter(this, void 0, void 0, function () {
3116
+ var maxSizeScale, maxWidth, options;
3117
+ var _this = this;
3118
+ return __generator(this, function (_a) {
3119
+ switch (_a.label) {
3120
+ case 0:
3121
+ maxSizeScale = 2;
3122
+ maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
3123
+ options = { crossOrigin: "anonymous" };
3124
+ return [4 /*yield*/, new Promise(function (resolve) {
3125
+ _this.fabric.Image.fromURL(imageUrl, function (fabricImage) {
3126
+ var id = _this.randomId();
3127
+ var newScale = 1;
3128
+ var curWidth = newScale * fabricImage.width;
3129
+ if (curWidth > maxWidth) {
3130
+ newScale = maxWidth / curWidth;
3131
+ }
3132
+ fabricImage.set({
3133
+ id: id,
3134
+ scaleX: newScale,
3135
+ scaleY: newScale
3136
+ });
3137
+ _this.fabricCanvas.add(fabricImage);
3138
+ var object = new RichText(_this, fabricImage);
3139
+ object.htmlContent = htmlContent;
3140
+ _this.trackNewObject(object);
3141
+ var margin = _this.getMargin();
3142
+ object.setImageWidth(_this.dimensions$.value.widthPx - margin.left - margin.right);
3143
+ _this.selectFabricObject(fabricImage);
3144
+ _this.syncObjectList();
3145
+ resolve(object);
3146
+ }, options);
3147
+ })];
3148
+ case 1: return [2 /*return*/, _a.sent()];
3149
+ }
3150
+ });
3151
+ });
3152
+ };
3153
+ /**
3154
+ * @override
3155
+ * @inheritDoc
3156
+ */
3157
+ AbstractInteractiveCanvas.prototype.addRectangleObject = function () {
3158
+ return __awaiter(this, void 0, void 0, function () {
3159
+ var canvasWidth, canvasHeight, rectWidth, rectHeight, rectangleOptions, fabricRect, object;
3160
+ return __generator(this, function (_a) {
3161
+ canvasWidth = this.getDimensions().widthPx;
3162
+ canvasHeight = this.getDimensions().heightPx;
3163
+ rectWidth = canvasWidth / 2;
3164
+ rectHeight = canvasHeight / 2;
3165
+ rectangleOptions = {
3166
+ id: this.randomId(),
3167
+ width: canvasWidth / 2,
3168
+ height: 2,
3169
+ top: canvasHeight / 2 - rectHeight / 2,
3170
+ left: canvasWidth / 2 - rectWidth / 2,
3171
+ fill: "#000000"
3172
+ };
3173
+ fabricRect = new this.fabric.Rect(rectangleOptions);
3174
+ this.fabricCanvas.add(fabricRect);
3175
+ object = new Rectangle(this, fabricRect);
3176
+ this.trackNewObject(object);
3177
+ this.selectFabricObject(fabricRect);
3178
+ this.syncObjectList();
3179
+ return [2 /*return*/, object];
3180
+ });
3181
+ });
3182
+ };
3183
+ /**
3184
+ * @override
3185
+ * @inheritDoc
3186
+ */
3187
+ AbstractInteractiveCanvas.prototype.addCutoffObject = function () {
3188
+ return __awaiter(this, void 0, void 0, function () {
3189
+ var profile, initialThickness, canvasWidth, canvasHeight, rectangleOptions, fabricRect, object;
3190
+ return __generator(this, function (_a) {
3191
+ profile = this.profile$.value;
3192
+ initialThickness = profile.defaultCutoffWidth;
3193
+ canvasWidth = this.getDimensions().widthPx;
3194
+ canvasHeight = this.getDimensions().heightPx;
3195
+ rectangleOptions = {
3196
+ id: this.randomId(),
3197
+ width: canvasWidth,
3198
+ height: initialThickness,
3199
+ top: canvasHeight - initialThickness,
3200
+ left: 0,
3201
+ fill: profile.defaultCutoffColor
3202
+ };
3203
+ fabricRect = new this.fabric.Rect(rectangleOptions);
3204
+ this.fabricCanvas.add(fabricRect);
3205
+ object = new Cutoff(this, fabricRect);
3206
+ this.trackNewObject(object);
3207
+ this.selectFabricObject(fabricRect);
3208
+ this.syncObjectList();
3209
+ return [2 /*return*/, object];
3210
+ });
3211
+ });
3212
+ };
3213
+ /**
3214
+ * @override
3215
+ * @inheritDoc
3216
+ */
3217
+ AbstractInteractiveCanvas.prototype.addBorderObject = function () {
3218
+ return __awaiter(this, void 0, void 0, function () {
3219
+ var profile, initialThickness, rectangleOptions, fabricRect, object;
3220
+ return __generator(this, function (_a) {
3221
+ profile = this.profile$.value;
3222
+ initialThickness = profile.defaultBorderWidth;
3223
+ rectangleOptions = {
3224
+ id: this.randomId(),
3225
+ fill: null,
3226
+ stroke: profile.defaultBorderColor,
3227
+ strokeWidth: initialThickness
3228
+ };
3229
+ fabricRect = new this.fabric.Rect(rectangleOptions);
3230
+ this.fabricCanvas.add(fabricRect);
3231
+ object = new Border(this, fabricRect);
3232
+ this.trackNewObject(object);
3233
+ this.selectFabricObject(fabricRect);
3234
+ this.syncObjectList();
3235
+ return [2 /*return*/, object];
3236
+ });
3237
+ });
3238
+ };
3239
+ /**
3240
+ * @override
3241
+ * @inheritDoc
3242
+ */
3243
+ AbstractInteractiveCanvas.prototype.addVerticalRuleObject = function () {
3244
+ return __awaiter(this, void 0, void 0, function () {
3245
+ var canvasHeight, rectOptions, fabricRect, object;
3246
+ return __generator(this, function (_a) {
3247
+ canvasHeight = this.fabricCanvas.getHeight();
3248
+ rectOptions = {
3249
+ id: this.randomId(),
3250
+ width: 1,
3251
+ height: canvasHeight,
3252
+ top: 0,
3253
+ left: 0,
3254
+ fill: "#000000"
3255
+ };
3256
+ fabricRect = new this.fabric.Rect(rectOptions);
3257
+ this.fabricCanvas.add(fabricRect);
3258
+ object = new VerticalRule(this, fabricRect);
3259
+ this.trackNewObject(object);
3260
+ this.selectFabricObject(fabricRect);
3261
+ this.syncObjectList();
3262
+ return [2 /*return*/, object];
3263
+ });
3264
+ });
3265
+ };
3266
+ /**
3267
+ * @override
3268
+ * @inheritDoc
3269
+ */
3270
+ AbstractInteractiveCanvas.prototype.addHorizontalRuleObject = function () {
3271
+ return __awaiter(this, void 0, void 0, function () {
3272
+ var rectOptions, fabricRect, object;
3273
+ return __generator(this, function (_a) {
3274
+ rectOptions = {
3275
+ id: this.randomId(),
3276
+ width: 10,
3277
+ height: 1,
3278
+ top: 0,
3279
+ left: 0,
3280
+ fill: "#000000"
3281
+ };
3282
+ fabricRect = new this.fabric.Rect(rectOptions);
3283
+ this.fabricCanvas.add(fabricRect);
3284
+ object = new HorizontalRule(this, fabricRect);
3285
+ this.trackNewObject(object);
3286
+ this.selectFabricObject(fabricRect);
3287
+ this.syncObjectList();
3288
+ return [2 /*return*/, object];
3289
+ });
3290
+ });
3291
+ };
3292
+ /**
3293
+ * @override
3294
+ * @inheritDoc
3295
+ */
3296
+ AbstractInteractiveCanvas.prototype.addBackgroundImageObject = function (imageUrl) {
3297
+ return __awaiter(this, void 0, void 0, function () {
3298
+ var options;
3299
+ var _this = this;
3300
+ return __generator(this, function (_a) {
3301
+ switch (_a.label) {
3302
+ case 0:
3303
+ options = { crossOrigin: "anonymous" };
3304
+ return [4 /*yield*/, new Promise(function (resolve) {
3305
+ _this.fabric.Image.fromURL(imageUrl, function (fabricImage) {
3306
+ var id = _this.randomId();
3307
+ fabricImage.set({
3308
+ id: id,
3309
+ });
3310
+ _this.fabricCanvas.add(fabricImage);
3311
+ var object = new BackgroundImage(_this, fabricImage);
3312
+ _this.trackNewObject(object);
3313
+ _this.selectFabricObject(fabricImage);
3314
+ _this.syncObjectList();
3315
+ resolve(object);
3316
+ }, options);
3317
+ })];
3318
+ case 1: return [2 /*return*/, _a.sent()];
3319
+ }
3320
+ });
3321
+ });
3322
+ };
3323
+ /**
3324
+ * @override
3325
+ * @inheritDoc
3326
+ */
3327
+ AbstractInteractiveCanvas.prototype.setPrefillData = function (data) {
3328
+ _(this.getObjectsByTypeInternal(ObjectType.TEXT)).each(function (object) {
3329
+ var prefillType = object.getPrefillType();
3330
+ if (prefillType !== undefined) {
3331
+ object.setText(data[prefillType] || "");
3332
+ }
3333
+ });
3334
+ };
3335
+ /**
3336
+ * @override
3337
+ * @inheritDoc
3338
+ */
3339
+ AbstractInteractiveCanvas.prototype.distributeObjectsVertically = function () {
3340
+ var margin = this.getMargin();
3341
+ var canvasHeight = this.getDimensions().heightPx;
3342
+ var objectsToLayout = _(this.getObjectsByTypesInternal(ObjectType.TEXT, ObjectType.IMAGE))
3343
+ .sortBy(function (x) { return x.getBoundingBox().top; })
3344
+ .value();
3345
+ var objectsHeight = reduce(objectsToLayout, function (total, element) { return total + element.getBoundingBox().height; }, 0);
3346
+ var workableHeight = canvasHeight - margin.top - margin.bottom;
3347
+ var requiredPadding = workableHeight - objectsHeight;
3348
+ var spaceBetween = requiredPadding / (objectsToLayout.length - 1);
3349
+ var nextElementTop = margin.top;
3350
+ for (var _i = 0, objectsToLayout_1 = objectsToLayout; _i < objectsToLayout_1.length; _i++) {
3351
+ var element = objectsToLayout_1[_i];
3352
+ var elementHeight = element.getBoundingBox().height;
3353
+ element.setPosition({
3354
+ top: nextElementTop
3355
+ });
3356
+ element.setCoords();
3357
+ nextElementTop += elementHeight + spaceBetween;
3358
+ }
3359
+ this.redraw();
3360
+ };
3361
+ /**
3362
+ * @override
3363
+ * @inheritDoc
3364
+ */
3365
+ AbstractInteractiveCanvas.prototype.getSelection = function () {
3366
+ return this.selection$.value;
3367
+ };
3368
+ /**
3369
+ * @override
3370
+ * @inheritDoc
3371
+ */
3372
+ AbstractInteractiveCanvas.prototype.getSelection$ = function () {
3373
+ return this.selection$;
3374
+ };
3375
+ /**
3376
+ * @override
3377
+ * @inheritDoc
3378
+ */
3379
+ AbstractInteractiveCanvas.prototype.select = function (object) {
3380
+ var concreteField = this.findObject(object.getId());
3381
+ if (!concreteField) {
3382
+ console.error("Attempted to select unknown object", object);
3383
+ return;
3384
+ }
3385
+ this.selectFabricObject(concreteField.getFabricObjectInternal());
3386
+ this.fabricCanvas.renderAll();
3387
+ };
3388
+ /**
3389
+ * @override
3390
+ * @inheritDoc
3391
+ */
3392
+ AbstractInteractiveCanvas.prototype.clearSelection = function () {
3393
+ this.fabricCanvas.discardActiveObject();
3394
+ this.fabricCanvas.renderAll();
3395
+ };
3396
+ AbstractInteractiveCanvas.prototype.setMultiSelect = function (value) {
3397
+ this.fabricCanvas.selection = value;
3398
+ this.fabricCanvas.selectionKey = value ? "shiftKey" : null;
3399
+ };
3400
+ /**
3401
+ * @override
3402
+ * @inheritDoc
3403
+ */
3404
+ AbstractInteractiveCanvas.prototype.clear = function () {
3405
+ this.fabricCanvas.clear();
3406
+ this.setBackgroundColor("#FFFFFF");
3407
+ this.objects$.next([]);
3408
+ };
3409
+ /**
3410
+ * @override
3411
+ * @inheritDoc
3412
+ */
3413
+ AbstractInteractiveCanvas.prototype.save = function () {
3414
+ var objects = _(this.objects$.value)
3415
+ .map(function (x) { return x.persist(); })
3416
+ .value();
3417
+ var includedProperties = ["id", "_isSlaveObject", "_isOrderedList", "_orderedListStart"];
3418
+ var json = this.fabricCanvas.toJSON(includedProperties);
3419
+ return {
3420
+ dimensions: this.dimensions$.value,
3421
+ canvasJson: JSON.stringify(json),
3422
+ objects: objects,
3423
+ backgroundColor: this.backgroundColor$.value
3424
+ };
3425
+ };
3426
+ /**
3427
+ * @override
3428
+ * @inheritDoc
3429
+ */
3430
+ AbstractInteractiveCanvas.prototype.load = function (canvasState) {
3431
+ return __awaiter(this, void 0, void 0, function () {
3432
+ var json_1;
3433
+ var _this = this;
3434
+ return __generator(this, function (_a) {
3435
+ switch (_a.label) {
3436
+ case 0:
3437
+ this.setBaseDimensions(canvasState.dimensions);
3438
+ if (!(canvasState.canvasJson != undefined)) return [3 /*break*/, 2];
3439
+ json_1 = JSON.parse(canvasState.canvasJson);
3440
+ return [4 /*yield*/, new Promise(function (resolve) {
3441
+ _this.fabricCanvas.loadFromJSON(json_1, function () { return resolve(); });
3442
+ })];
3443
+ case 1:
3444
+ _a.sent();
3445
+ _a.label = 2;
3446
+ case 2:
3447
+ if (canvasState.backgroundColor)
3448
+ this.setBackgroundColor(canvasState.backgroundColor);
3449
+ this.backgroundColor$.next(this.fabricCanvas.backgroundColor);
3450
+ this.bindFields(canvasState.objects);
3451
+ this.removePersistedBullets();
3452
+ this.removeSlaveObjects();
3453
+ this.layoutManager$.value.onInit();
3454
+ return [2 /*return*/];
3455
+ }
3456
+ });
3457
+ });
3458
+ };
3459
+ /**
3460
+ * Another hack for bullet points... because they use canvas objects to render the bullets, they get saved when the canvas is persisted... and then loaded into a new canvas, but there's
3461
+ * nothing linking them to the field that needs bullets, so they end up duplicating every time the canvas is saved/loaded. Since we don't use circles for anything else, this just
3462
+ * deletes all circles on canvas load.
3463
+ */
3464
+ AbstractInteractiveCanvas.prototype.removePersistedBullets = function () {
3465
+ var _this = this;
3466
+ var objects = this.fabricCanvas.getObjects();
3467
+ each(objects, function (object) {
3468
+ if (object.type === "circle")
3469
+ _this.removeFabricObject(object);
3470
+ });
3471
+ };
3472
+ /**
3473
+ * Remove any slave objects persisted to the canvas; their master objects will recreate them.
3474
+ */
3475
+ AbstractInteractiveCanvas.prototype.removeSlaveObjects = function () {
3476
+ var _this = this;
3477
+ var objects = this.fabricCanvas.getObjects();
3478
+ each(objects, function (object) {
3479
+ if (object._isSlaveObject)
3480
+ _this.removeFabricObject(object);
3481
+ });
3482
+ };
3483
+ /**
3484
+ * @override
3485
+ * @inheritDoc
3486
+ */
3487
+ AbstractInteractiveCanvas.prototype.toSvg = function () {
3488
+ var _this = this;
3489
+ var widthInMm = round(this.dimensions$.value.widthMm, 1) + "mm";
3490
+ var heightInMm = round(this.dimensions$.value.heightMm, 1) + "mm";
3491
+ var options = {
3492
+ width: widthInMm,
3493
+ height: heightInMm,
3494
+ suppressPreamble: true,
3495
+ encoding: null
3496
+ };
3497
+ var svg = this.executeWithNormalizedCanvas(function () { return _this.fabricCanvas.toSVG(options); });
3498
+ this.redraw();
3499
+ return svg;
3500
+ };
3501
+ /**
3502
+ * @override
3503
+ * @inheritDoc
3504
+ */
3505
+ AbstractInteractiveCanvas.prototype.toImage = function (multiplier) {
3506
+ var _this = this;
3507
+ console.log("Multiplier in interactive canvas : %s", multiplier);
3508
+ var activeObject = this.fabricCanvas.getActiveObject();
3509
+ this.fabricCanvas.discardActiveObject().renderAll();
3510
+ var options = {
3511
+ format: "png",
3512
+ multiplier: multiplier || this.IMAGE_CAPTURE_COEFFICIENT,
3513
+ enableRetinaScaling: true
3514
+ };
3515
+ var base64 = this.executeWithNormalizedCanvas(function () { return _this.fabricCanvas.toDataURL(options); });
3516
+ if (activeObject) {
3517
+ this.fabricCanvas.setActiveObject(activeObject);
3518
+ }
3519
+ return replace(base64, /^data:.*;base64,/, "");
3520
+ };
3521
+ /**
3522
+ * @override
3523
+ * @inheritDoc
3524
+ */
3525
+ AbstractInteractiveCanvas.prototype.createPNGStream = function () {
3526
+ return this.fabricCanvas.createPNGStream();
3527
+ };
3528
+ /**
3529
+ * @override
3530
+ * @inheritDoc
3531
+ */
3532
+ AbstractInteractiveCanvas.prototype.registerUndoState = function () {
3533
+ throw Error("Undo not supported on this canvas type");
3534
+ };
3535
+ /**
3536
+ * @override
3537
+ * @inheritDoc
3538
+ */
3539
+ AbstractInteractiveCanvas.prototype.undo = function () {
3540
+ throw Error("Undo not supported on this canvas type");
3541
+ };
3542
+ /**
3543
+ * @override
3544
+ * @inheritDoc
3545
+ */
3546
+ AbstractInteractiveCanvas.prototype.redo = function () {
3547
+ throw Error("Redo not supported on this canvas type");
3548
+ };
3549
+ /**
3550
+ * Redraw the canvas.
3551
+ */
3552
+ AbstractInteractiveCanvas.prototype.redraw = function () {
3553
+ this.fabricCanvas.renderAll();
3554
+ };
3555
+ AbstractInteractiveCanvas.prototype.syncObjectList = function () {
3556
+ var _this = this;
3557
+ var newObjectList = _(this.fabricCanvas.getObjects())
3558
+ .map(function (obj) { return _this.findObject(obj.id); })
3559
+ .filter(function (x) { return x !== undefined; })
3560
+ .value();
3561
+ this.objects$.next(newObjectList);
3562
+ this.onObjectListChange();
3563
+ };
3564
+ /**
3565
+ * @override
3566
+ * @inheritDoc
3567
+ */
3568
+ AbstractInteractiveCanvas.prototype.notifyObjectListChanged = function () {
3569
+ this.onObjectListChange();
3570
+ };
3571
+ /**
3572
+ * @override
3573
+ * @inheritDoc
3574
+ */
3575
+ AbstractInteractiveCanvas.prototype.notifyTextChanged = function () {
3576
+ this.onTextChange();
3577
+ };
3578
+ /**
3579
+ * @override
3580
+ * @inheritDoc
3581
+ */
3582
+ AbstractInteractiveCanvas.prototype.notifyMarginChanged = function () {
3583
+ this.onMarginChange();
3584
+ };
3585
+ AbstractInteractiveCanvas.prototype.removeFabricObject = function (obj) {
3586
+ this.fabricCanvas.remove(obj);
3587
+ };
3588
+ AbstractInteractiveCanvas.prototype.selectFabricObject = function (object) {
3589
+ this.fabricCanvas.setActiveObject(object);
3590
+ };
3591
+ AbstractInteractiveCanvas.prototype.onTextChange = function () {
3592
+ this.layoutManager$.value.onTextChange();
3593
+ };
3594
+ AbstractInteractiveCanvas.prototype.onObjectListChange = function () {
3595
+ this.layoutManager$.value.onObjectListChange();
3596
+ };
3597
+ AbstractInteractiveCanvas.prototype.onDimensionsChange = function () {
3598
+ this.layoutManager$.value.onCanvasDimensionsChange();
3599
+ };
3600
+ AbstractInteractiveCanvas.prototype.onMarginChange = function () {
3601
+ this.layoutManager$.value.onMarginChange();
3602
+ };
3603
+ AbstractInteractiveCanvas.prototype.bindFields = function (persistedFields) {
3604
+ var _this = this;
3605
+ var bound = _(persistedFields)
3606
+ .flatMap(function (field) {
3607
+ try {
3608
+ return [_this.bindField(field)];
3609
+ }
3610
+ catch (e) {
3611
+ console.error("Could not bind field", e, field);
3612
+ return []; //skip
3613
+ }
3614
+ })
3615
+ .value();
3616
+ this.objects$.next(bound);
3617
+ };
3618
+ AbstractInteractiveCanvas.prototype.bindField = function (persistedField) {
3619
+ var fabricObject = this.findFabricObject(persistedField.id);
3620
+ switch (persistedField.type) {
3621
+ case ObjectType.TEXT:
3622
+ return new Text(this, fabricObject, persistedField);
3623
+ case ObjectType.RECTANGLE:
3624
+ return new Rectangle(this, fabricObject, persistedField);
3625
+ case ObjectType.BORDER:
3626
+ return new Border(this, fabricObject, persistedField);
3627
+ case ObjectType.CUTOFF:
3628
+ return new Cutoff(this, fabricObject, persistedField);
3629
+ case ObjectType.IMAGE:
3630
+ case ObjectType.LIBRARY_IMAGE:
3631
+ return new Image(this, fabricObject, persistedField);
3632
+ case ObjectType.HORIZONTAL_RULE:
3633
+ return new HorizontalRule(this, fabricObject, persistedField);
3634
+ case ObjectType.VERTICAL_RULE:
3635
+ return new VerticalRule(this, fabricObject, persistedField);
3636
+ case ObjectType.RICH_TEXT:
3637
+ return new RichText(this, fabricObject, persistedField);
3638
+ case ObjectType.BACKGROUND_IMAGE:
3639
+ return new BackgroundImage(this, fabricObject, persistedField);
3640
+ default:
3641
+ throw new Error("Unknown field type: [" + persistedField.type + "]");
3642
+ }
3643
+ };
3644
+ AbstractInteractiveCanvas.prototype.findFabricObject = function (id) {
3645
+ var objects = this.fabricCanvas.getObjects();
3646
+ var fabricObject = find(objects, function (o) { return o.id == id; });
3647
+ if (!fabricObject) {
3648
+ throw new Error("Cannot find fabric object with id [" + id + "]");
3649
+ }
3650
+ return fabricObject;
3651
+ };
3652
+ AbstractInteractiveCanvas.prototype.findObject = function (id) {
3653
+ //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; });
3655
+ };
3656
+ /**
3657
+ * Reset zoom and canvas dimensions to 1:1 scale, execute a function, then return the canvas to
3658
+ * the previous values.
3659
+ * @param func Function to execute.
3660
+ */
3661
+ AbstractInteractiveCanvas.prototype.executeWithNormalizedCanvas = function (func) {
3662
+ this.updateCanvasDimensions(this.dimensions$.value, 1);
3663
+ var response;
3664
+ try {
3665
+ response = func();
3666
+ }
3667
+ finally {
3668
+ this.updateCanvasDimensions(this.dimensions$.value, this.zoom$.value);
3669
+ }
3670
+ return response;
3671
+ };
3672
+ /**
3673
+ * Update the actual dimensions of the canvas by multiplying the requested dimensions by the current zoom factor.
3674
+ */
3675
+ AbstractInteractiveCanvas.prototype.updateCanvasDimensions = function (dims, zoom) {
3676
+ var width = dims.widthPx * zoom;
3677
+ var height = dims.heightPx * zoom;
3678
+ this.fabricCanvas.setZoom(zoom);
3679
+ this.fabricCanvas.setDimensions({
3680
+ width: width,
3681
+ height: height
3682
+ });
3683
+ };
3684
+ AbstractInteractiveCanvas.prototype.onProfileChanged = function (profile) {
3685
+ this.setMultiSelect(profile.allowMultiSelect);
3686
+ this.layoutManager$.value.onProfileChange(profile);
3687
+ };
3688
+ AbstractInteractiveCanvas.prototype.getFieldByCanvasObject = function (object) {
3689
+ if (!object) {
3690
+ return null;
3691
+ }
3692
+ return find(this.objects$.value, function (field) { return field.getId() == object.id; });
3693
+ };
3694
+ AbstractInteractiveCanvas.prototype.getFieldsByCanvasObject = function (objects) {
3695
+ var _this = this;
3696
+ return _(objects)
3697
+ .map(function (obj) { return _this.getFieldByCanvasObject(obj); })
3698
+ .reject(function (x) { return !x; })
3699
+ .value();
3700
+ };
3701
+ AbstractInteractiveCanvas.prototype.calculateImageCaptureCoefficient = function () {
3702
+ var precision = 3;
3703
+ var devicePixelRatio = this.devicePixelRatio || 1;
3704
+ return round(2 / devicePixelRatio, precision);
3705
+ };
3706
+ AbstractInteractiveCanvas.prototype.randomId = function () {
3707
+ var min = 0;
3708
+ var max = 999;
3709
+ var id = Math.floor(Math.random() * (max - min)) + min;
3710
+ return (new Date()).getTime() + "" + id;
3711
+ };
3712
+ AbstractInteractiveCanvas.prototype.getLowestTextPoint = function () {
3713
+ return _(this.objects$.value)
3714
+ .filter(function (object) { return object.getType() === ObjectType.TEXT; })
3715
+ .map(function (text) { return text.getDimensions().top.px + text.getDimensions().height.px; })
3716
+ .reduce(function (x, y) { return Math.max(x, y); }, 0);
3717
+ };
3718
+ AbstractInteractiveCanvas.prototype.trackNewObject = function (object) {
3719
+ this.objects$.next(__spreadArrays(this.objects$.value, [object]));
3720
+ };
3721
+ AbstractInteractiveCanvas.prototype.dimensionsExceedRestrictions = function (dimensions) {
3722
+ 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();
3729
+ };
3730
+ return AbstractInteractiveCanvas;
3731
+ }());
3732
+ var SelectionData = /** @class */ (function () {
3733
+ function SelectionData(objects) {
3734
+ this.objects = objects;
3735
+ this.empty = this.objects.length < 1;
3736
+ var selectedObject = this.objects[0];
3737
+ this.isText = selectedObject
3738
+ && selectedObject.getType() === ObjectType.TEXT
3739
+ && selectedObject.isEditing();
3740
+ }
3741
+ return SelectionData;
3742
+ }());
3743
+
3744
+ var HeadlessInteractiveCanvas = /** @class */ (function (_super) {
3745
+ __extends(HeadlessInteractiveCanvas, _super);
3746
+ function HeadlessInteractiveCanvas() {
3747
+ var _this = _super.call(this, fabric, new fabric.StaticCanvas(null, { width: 640, height: 480 }), null) || this;
3748
+ _this.headless = true;
3749
+ return _this;
3750
+ }
3751
+ /**
3752
+ * @override
3753
+ */
3754
+ HeadlessInteractiveCanvas.prototype.selectFabricObject = function (object) {
3755
+ //no-op
3756
+ };
3757
+ return HeadlessInteractiveCanvas;
3758
+ }(AbstractInteractiveCanvas));
3759
+
3760
+ var UndoStack = /** @class */ (function () {
3761
+ function UndoStack(canvas, size) {
3762
+ if (size === void 0) { size = 100; }
3763
+ this.canvas = canvas;
3764
+ this.undoStates = [];
3765
+ this.redoStates = [];
3766
+ this.lastState = null;
3767
+ this.size = size;
3768
+ }
3769
+ /**
3770
+ * @override
3771
+ * @inheritDoc
3772
+ */
3773
+ UndoStack.prototype.save = function (state) {
3774
+ var currentState = this.canvas.save();
3775
+ var undoState = this.undoStates[this.undoStates.length - 1];
3776
+ if (isEqual(undoState, state))
3777
+ return;
3778
+ this.undoStates.push(state);
3779
+ if (this.undoStates.length > this.size)
3780
+ this.undoStates.splice(0, 1);
3781
+ this.clearRedoStackIfCanvasChanged(currentState);
3782
+ };
3783
+ /**
3784
+ * @override
3785
+ * @inheritDoc
3786
+ */
3787
+ UndoStack.prototype.undo = function () {
3788
+ return __awaiter(this, void 0, void 0, function () {
3789
+ var undoState, currentState;
3790
+ return __generator(this, function (_a) {
3791
+ switch (_a.label) {
3792
+ case 0:
3793
+ undoState = this.undoStates.pop();
3794
+ if (!undoState)
3795
+ return [2 /*return*/];
3796
+ currentState = this.canvas.save();
3797
+ if (isEqual(undoState, currentState)) {
3798
+ undoState = this.undoStates.pop();
3799
+ if (!undoState)
3800
+ return [2 /*return*/];
3801
+ }
3802
+ this.lastState = undoState;
3803
+ this.redoStates.push(currentState);
3804
+ return [4 /*yield*/, this.canvas.load(undoState)];
3805
+ case 1:
3806
+ _a.sent();
3807
+ return [2 /*return*/];
3808
+ }
3809
+ });
3810
+ });
3811
+ };
3812
+ /**
3813
+ * @override
3814
+ * @inheritDoc
3815
+ */
3816
+ UndoStack.prototype.redo = function () {
3817
+ return __awaiter(this, void 0, void 0, function () {
3818
+ var redoState, currentState;
3819
+ return __generator(this, function (_a) {
3820
+ switch (_a.label) {
3821
+ case 0:
3822
+ redoState = this.redoStates.pop();
3823
+ if (!redoState)
3824
+ return [2 /*return*/];
3825
+ currentState = this.canvas.save();
3826
+ this.lastState = redoState;
3827
+ this.undoStates.push(currentState);
3828
+ return [4 /*yield*/, this.canvas.load(redoState)];
3829
+ case 1:
3830
+ _a.sent();
3831
+ return [2 /*return*/];
3832
+ }
3833
+ });
3834
+ });
3835
+ };
3836
+ UndoStack.prototype.clearRedoStackIfCanvasChanged = function (currentState) {
3837
+ if (isEqual(this.lastState, currentState))
3838
+ return;
3839
+ this.redoStates = [];
3840
+ };
3841
+ return UndoStack;
3842
+ }());
3843
+
3844
+ var InteractiveCanvas = /** @class */ (function (_super) {
3845
+ __extends(InteractiveCanvas, _super);
3846
+ function InteractiveCanvas(canvas, devicePixelRatio) {
3847
+ var _this = _super.call(this, window['fabric'], new window['fabric'].Canvas(canvas), devicePixelRatio) || this;
3848
+ _this.devicePixelRatio = devicePixelRatio;
3849
+ _this.headless = false;
3850
+ _this.undoStack = new UndoStack(_this);
3851
+ //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(); });
3855
+ _this.fabricCanvas.on("text:editing:entered", function () { return _this.onTextEditing(); });
3856
+ _this.fabricCanvas.on("text:editing:exited", function () { return _this.onTextEditing(); });
3857
+ _this.fabricCanvas.on("text:changed", function () { return _this.onTextChange(); });
3858
+ return _this;
3859
+ }
3860
+ /**
3861
+ * @override
3862
+ * @inheritDoc
3863
+ */
3864
+ InteractiveCanvas.prototype.registerUndoState = function () {
3865
+ this.undoStack.save(this.save());
3866
+ };
3867
+ /**
3868
+ * @override
3869
+ * @inheritDoc
3870
+ */
3871
+ InteractiveCanvas.prototype.undo = function () {
3872
+ return __awaiter(this, void 0, void 0, function () {
3873
+ return __generator(this, function (_a) {
3874
+ switch (_a.label) {
3875
+ case 0: return [4 /*yield*/, this.undoStack.undo()];
3876
+ case 1:
3877
+ _a.sent();
3878
+ return [2 /*return*/];
3879
+ }
3880
+ });
3881
+ });
3882
+ };
3883
+ /**
3884
+ * @override
3885
+ * @inheritDoc
3886
+ */
3887
+ InteractiveCanvas.prototype.redo = function () {
3888
+ return __awaiter(this, void 0, void 0, function () {
3889
+ return __generator(this, function (_a) {
3890
+ switch (_a.label) {
3891
+ case 0: return [4 /*yield*/, this.undoStack.redo()];
3892
+ case 1:
3893
+ _a.sent();
3894
+ return [2 /*return*/];
3895
+ }
3896
+ });
3897
+ });
3898
+ };
3899
+ InteractiveCanvas.prototype.onFabricSelectionChanged = function () {
3900
+ var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
3901
+ this.selection$.next(new SelectionData(selected));
3902
+ this.enterTextSelectionModeIfRequired();
3903
+ };
3904
+ InteractiveCanvas.prototype.enterTextSelectionModeIfRequired = function () {
3905
+ if (!this.profile$.value.enterTextEditImmediatelyOnSelect && !this.layoutManager$.value.enterTextEditImmediatelyOnSelect)
3906
+ return;
3907
+ if (!this.selection$.value || !this.selection$.value.objects[0] || this.selection$.value.objects[0].getType() !== ObjectType.TEXT)
3908
+ return;
3909
+ var text = this.selection$.value.objects[0];
3910
+ text.enterEditing();
3911
+ };
3912
+ InteractiveCanvas.prototype.onTextEditing = function () {
3913
+ var selected = this.getFieldsByCanvasObject(this.fabricCanvas.getActiveObjects());
3914
+ this.selection$.next(new SelectionData(selected));
3915
+ };
3916
+ return InteractiveCanvas;
3917
+ }(AbstractInteractiveCanvas));
3918
+
3919
+ var RepositionCutoffsLayoutFunction = /** @class */ (function () {
3920
+ function RepositionCutoffsLayoutFunction() {
3921
+ }
3922
+ RepositionCutoffsLayoutFunction.prototype.execute = function (canvas) {
3923
+ canvas.getObjectsByTypeInternal(ObjectType.CUTOFF)
3924
+ .forEach(function (cutoff) { return cutoff.updatePosition(); });
3925
+ };
3926
+ return RepositionCutoffsLayoutFunction;
3927
+ }());
3928
+
3929
+ var PinToBottomLayoutFunction = /** @class */ (function () {
3930
+ function PinToBottomLayoutFunction() {
3931
+ }
3932
+ PinToBottomLayoutFunction.prototype.execute = function (canvas) {
3933
+ canvas.getObjectsInternal()
3934
+ .forEach(function (object) { return object.moveToPinnedPosition(); });
3935
+ };
3936
+ return PinToBottomLayoutFunction;
3937
+ }());
3938
+
3939
+ var ResizeCanvasLayoutFunction = /** @class */ (function () {
3940
+ function ResizeCanvasLayoutFunction() {
3941
+ }
3942
+ ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
3943
+ if (canvas.getLayoutManager().isEnforcedPositioning)
3944
+ return;
3945
+ if (oc(canvas.getDimensionsRestrictions()).fixed(false))
3946
+ return;
3947
+ var currentDimensions = canvas.getDimensions();
3948
+ var baseDimensions = canvas.getBaseDimensions();
3949
+ var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(ObjectType.TEXT))
3950
+ .filter(function (text) { return text.isResizeCanvas(); })
3951
+ .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
3952
+ var increase = baseDimensions.withSize(currentDimensions.width, 0);
3953
+ while (increase.heightPx < textHeightIncreasePx) {
3954
+ increase = increase.withSize(increase.width, increase.height + 1);
3955
+ }
3956
+ var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
3957
+ if (currentDimensions.height !== targetHeight.height) {
3958
+ canvas.setDimensions(targetHeight);
3959
+ }
3960
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
3961
+ canvas.redraw();
3962
+ };
3963
+ return ResizeCanvasLayoutFunction;
3964
+ }());
3965
+
3966
+ var AdvancedLayoutManager = /** @class */ (function (_super) {
3967
+ __extends(AdvancedLayoutManager, _super);
3968
+ function AdvancedLayoutManager(canvas) {
3969
+ var _this = _super.call(this, canvas) || this;
3970
+ _this.key = LayoutManager.ADVANCED;
3971
+ _this.pinToBottom = new PinToBottomLayoutFunction();
3972
+ _this.redrawAll = new RedrawAllLayoutFunction();
3973
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
3974
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
3975
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
3976
+ _this.resizeCanvas = new ResizeCanvasLayoutFunction();
3977
+ return _this;
3978
+ }
3979
+ AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
3980
+ this.pinToBottom.execute(this.canvas);
3981
+ this.repositionCutoffs.execute(this.canvas);
3982
+ this.repositionBorders.execute(this.canvas);
3983
+ this.repositionBackgrounds.execute(this.canvas);
3984
+ this.redrawAll.execute(this.canvas);
3985
+ };
3986
+ AdvancedLayoutManager.prototype.onTextChange = function () {
3987
+ this.resizeCanvas.execute(this.canvas);
3988
+ };
3989
+ AdvancedLayoutManager.prototype.onObjectListChange = function () {
3990
+ this.redrawAll.execute(this.canvas);
3991
+ };
3992
+ return AdvancedLayoutManager;
3993
+ }(AbstractLayoutManager));
3994
+
3995
+ export { AbstractCanvasObject, AbstractInteractiveCanvas, AbstractLayoutManager, AdvancedLayoutManager, BackgroundImage, Border, CanvasObjectData, Cutoff, DefaultCanvasProfile, Font, FontLibrary, HeadlessInteractiveCanvas, HorizontalRule, Image, ImageType, InteractiveCanvas, LayoutManager, MillimeterDimensions, ObjectType, PixelCanvasDimensions, Print6ColCanvasDimensions, Print8ColCanvasDimensions, Rectangle, RichText, SelectionData, StandardLayoutManager, Text, UNKNOWN_FONT, UnknownFont, VerticalRule, isMutableBackgroundColor, isMutableColor, isMutableImage, isMutablePosition, isMutableStroke, isMutableText, isMutableTextStyle };