@leapfrog/interactive-canvas 2.0.8 → 2.0.9

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,4028 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _ = require('lodash');
6
+ var tsOptchain = require('ts-optchain');
7
+ var rxjs = require('rxjs');
8
+ var fabric = require('fabric');
9
+
10
+ var PIXELS_PER_MM = 3.937;
11
+ var MillimeterDimensions = /** @class */ (function () {
12
+ function MillimeterDimensions(width, height) {
13
+ this.widthUnit = "mm";
14
+ this.heightUnit = "mm";
15
+ this.width = width;
16
+ this.widthMm = Math.max(0, width);
17
+ this.widthPx = _.round(this.widthMm * PIXELS_PER_MM);
18
+ this.height = height;
19
+ this.heightMm = Math.max(0, height);
20
+ this.heightPx = _.round(this.heightMm * PIXELS_PER_MM);
21
+ }
22
+ MillimeterDimensions.prototype.withSize = function (width, height) {
23
+ return new MillimeterDimensions(width, height);
24
+ };
25
+ MillimeterDimensions.prototype.widthPxToMm = function (px) {
26
+ return px / PIXELS_PER_MM;
27
+ };
28
+ MillimeterDimensions.prototype.heightPxToMm = function (px) {
29
+ return px / PIXELS_PER_MM;
30
+ };
31
+ return MillimeterDimensions;
32
+ }());
33
+
34
+ var PixelCanvasDimensions = /** @class */ (function () {
35
+ function PixelCanvasDimensions(width, height) {
36
+ this.widthUnit = "px";
37
+ this.heightUnit = "px";
38
+ this.width = width;
39
+ this.widthPx = width;
40
+ this.height = height;
41
+ this.heightPx = height;
42
+ }
43
+ PixelCanvasDimensions.prototype.withSize = function (width, height) {
44
+ return new PixelCanvasDimensions(width, height);
45
+ };
46
+ PixelCanvasDimensions.prototype.widthPxToMm = function (px) {
47
+ return void 0;
48
+ };
49
+ PixelCanvasDimensions.prototype.heightPxToMm = function (px) {
50
+ return void 0;
51
+ };
52
+ return PixelCanvasDimensions;
53
+ }());
54
+
55
+ var COLUMN_WIDTH_MM = 41;
56
+ var GUTTER_WIDTH_MM = 3;
57
+ var PIXELS_PER_MM$1 = 3.937;
58
+ var Print6ColCanvasDimensions = /** @class */ (function () {
59
+ function Print6ColCanvasDimensions(width, height) {
60
+ this.widthUnit = "column(s)";
61
+ this.heightUnit = "cm";
62
+ this.width = width;
63
+ this.gutterCount = Math.max(0, width - 1);
64
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM;
65
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM;
66
+ this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
67
+ this.widthPx = _.round(this.widthMm * PIXELS_PER_MM$1);
68
+ this.height = height;
69
+ this.heightMm = Math.max(0, height * 10);
70
+ this.heightPx = _.round(this.heightMm * PIXELS_PER_MM$1);
71
+ }
72
+ Print6ColCanvasDimensions.prototype.withSize = function (width, height) {
73
+ return new Print6ColCanvasDimensions(width, height);
74
+ };
75
+ Print6ColCanvasDimensions.prototype.widthPxToMm = function (px) {
76
+ return px / PIXELS_PER_MM$1;
77
+ };
78
+ Print6ColCanvasDimensions.prototype.heightPxToMm = function (px) {
79
+ return px / PIXELS_PER_MM$1;
80
+ };
81
+ return Print6ColCanvasDimensions;
82
+ }());
83
+
84
+ var COLUMN_WIDTH_MM$1 = 30.8772;
85
+ var GUTTER_WIDTH_MM$1 = 2.1053;
86
+ var PIXELS_PER_MM$2 = 3.937;
87
+ var Print8ColCanvasDimensions = /** @class */ (function () {
88
+ function Print8ColCanvasDimensions(width, height) {
89
+ this.widthUnit = "column(s)";
90
+ this.heightUnit = "cm";
91
+ this.width = width;
92
+ this.gutterCount = Math.max(0, width - 1);
93
+ this.gutterTotalMm = this.gutterCount * GUTTER_WIDTH_MM$1;
94
+ this.columnsTotalMm = width * COLUMN_WIDTH_MM$1;
95
+ this.widthMm = Math.max(0, this.columnsTotalMm + this.gutterTotalMm);
96
+ this.widthPx = _.round(this.widthMm * PIXELS_PER_MM$2);
97
+ this.height = height;
98
+ this.heightMm = Math.max(0, height * 10);
99
+ this.heightPx = _.round(this.heightMm * PIXELS_PER_MM$2);
100
+ }
101
+ Print8ColCanvasDimensions.prototype.withSize = function (width, height) {
102
+ return new Print8ColCanvasDimensions(width, height);
103
+ };
104
+ Print8ColCanvasDimensions.prototype.widthPxToMm = function (px) {
105
+ return px / PIXELS_PER_MM$2;
106
+ };
107
+ Print8ColCanvasDimensions.prototype.heightPxToMm = function (px) {
108
+ return px / PIXELS_PER_MM$2;
109
+ };
110
+ return Print8ColCanvasDimensions;
111
+ }());
112
+
113
+ /*! *****************************************************************************
114
+ Copyright (c) Microsoft Corporation.
115
+
116
+ Permission to use, copy, modify, and/or distribute this software for any
117
+ purpose with or without fee is hereby granted.
118
+
119
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
120
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
121
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
122
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
123
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
124
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
125
+ PERFORMANCE OF THIS SOFTWARE.
126
+ ***************************************************************************** */
127
+ /* global Reflect, Promise */
128
+
129
+ var extendStatics = function(d, b) {
130
+ extendStatics = Object.setPrototypeOf ||
131
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
132
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
133
+ return extendStatics(d, b);
134
+ };
135
+
136
+ function __extends(d, b) {
137
+ extendStatics(d, b);
138
+ function __() { this.constructor = d; }
139
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
140
+ }
141
+
142
+ function __awaiter(thisArg, _arguments, P, generator) {
143
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
144
+ return new (P || (P = Promise))(function (resolve, reject) {
145
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
146
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
147
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
148
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
149
+ });
150
+ }
151
+
152
+ function __generator(thisArg, body) {
153
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
154
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
155
+ function verb(n) { return function (v) { return step([n, v]); }; }
156
+ function step(op) {
157
+ if (f) throw new TypeError("Generator is already executing.");
158
+ while (_) try {
159
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
160
+ if (y = 0, t) op = [op[0] & 2, t.value];
161
+ switch (op[0]) {
162
+ case 0: case 1: t = op; break;
163
+ case 4: _.label++; return { value: op[1], done: false };
164
+ case 5: _.label++; y = op[1]; op = [0]; continue;
165
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
166
+ default:
167
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
168
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
169
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
170
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
171
+ if (t[2]) _.ops.pop();
172
+ _.trys.pop(); continue;
173
+ }
174
+ op = body.call(thisArg, _);
175
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
176
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
177
+ }
178
+ }
179
+
180
+ function __spreadArrays() {
181
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
182
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
183
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
184
+ r[k] = a[j];
185
+ return r;
186
+ }
187
+
188
+ var Font = /** @class */ (function () {
189
+ function Font() {
190
+ }
191
+ /**
192
+ * @override
193
+ * @inheritDoc
194
+ */
195
+ Font.prototype.isBold = function (fontWeight) {
196
+ return fontWeight === this.boldWeight;
197
+ };
198
+ return Font;
199
+ }());
200
+
201
+ var UnknownFont = /** @class */ (function (_super) {
202
+ __extends(UnknownFont, _super);
203
+ function UnknownFont() {
204
+ var _this = _super !== null && _super.apply(this, arguments) || this;
205
+ _this.family = "_Unknown_";
206
+ _this.normalWeight = 400;
207
+ _this.boldWeight = 700;
208
+ return _this;
209
+ }
210
+ return UnknownFont;
211
+ }(Font));
212
+
213
+ var UNKNOWN_FONT = new UnknownFont();
214
+ var FontLibrary = /** @class */ (function () {
215
+ function FontLibrary() {
216
+ this._fonts = {};
217
+ }
218
+ /**
219
+ * @override
220
+ * @inheritDoc
221
+ */
222
+ FontLibrary.prototype.registerFont = function (font) {
223
+ this._fonts[font.family] = font;
224
+ };
225
+ /**
226
+ * @override
227
+ * @inheritDoc
228
+ */
229
+ FontLibrary.prototype.registerFonts = function (fonts) {
230
+ var _this = this;
231
+ _.each(fonts, function (font) { return _this._fonts[font.family] = font; });
232
+ };
233
+ /**
234
+ * @override
235
+ * @inheritDoc
236
+ */
237
+ FontLibrary.prototype.getFonts = function () {
238
+ return _.values(this._fonts);
239
+ };
240
+ /**
241
+ * @override
242
+ * @inheritDoc
243
+ */
244
+ FontLibrary.prototype.getFont = function (family) {
245
+ return this._fonts[family] || UNKNOWN_FONT;
246
+ };
247
+ return FontLibrary;
248
+ }());
249
+
250
+ var AbstractLayoutManager = /** @class */ (function () {
251
+ function AbstractLayoutManager(canvas) {
252
+ this.isEnforcedPositioning = false;
253
+ this.enterTextEditImmediatelyOnSelect = false;
254
+ this.canvas = canvas;
255
+ }
256
+ AbstractLayoutManager.prototype.getCanvas = function () {
257
+ return this.canvas;
258
+ };
259
+ AbstractLayoutManager.prototype.onInit = function () {
260
+ //noop
261
+ };
262
+ AbstractLayoutManager.prototype.onProfileChange = function (profile) {
263
+ //noop
264
+ };
265
+ AbstractLayoutManager.prototype.onCanvasDimensionsChange = function () {
266
+ //noop
267
+ };
268
+ AbstractLayoutManager.prototype.onTextChange = function () {
269
+ //noop
270
+ };
271
+ AbstractLayoutManager.prototype.onObjectListChange = function () {
272
+ //noop
273
+ };
274
+ AbstractLayoutManager.prototype.onMarginChange = function () {
275
+ //noop
276
+ };
277
+ return AbstractLayoutManager;
278
+ }());
279
+
280
+ var RedrawAllLayoutFunction = /** @class */ (function () {
281
+ function RedrawAllLayoutFunction() {
282
+ }
283
+ RedrawAllLayoutFunction.prototype.execute = function (canvas) {
284
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
285
+ canvas.redraw();
286
+ };
287
+ return RedrawAllLayoutFunction;
288
+ }());
289
+
290
+ (function (LayoutManager) {
291
+ LayoutManager["LEGACY"] = "LEGACY";
292
+ LayoutManager["STANDARD"] = "STANDARD";
293
+ LayoutManager["ADVANCED"] = "ADVANCED";
294
+ })(exports.LayoutManager || (exports.LayoutManager = {}));
295
+
296
+ var UpdateObjectDimensionsLayoutFunction = /** @class */ (function () {
297
+ function UpdateObjectDimensionsLayoutFunction() {
298
+ }
299
+ UpdateObjectDimensionsLayoutFunction.prototype.execute = function (canvas) {
300
+ canvas.getObjectsInternal().forEach(function (object) { return object.updateDimensions(); });
301
+ };
302
+ return UpdateObjectDimensionsLayoutFunction;
303
+ }());
304
+
305
+ var MIN_MAGNITUDE = 1;
306
+ var StackObjectsLayoutFunction = /** @class */ (function () {
307
+ function StackObjectsLayoutFunction() {
308
+ }
309
+ StackObjectsLayoutFunction.prototype.execute = function (canvas) {
310
+ var canvasMargin = canvas.getMargin();
311
+ var canvasDimensions = canvas.getDimensions();
312
+ var allObjects = canvas.getObjectsByTypesInternal(exports.ObjectType.TEXT, exports.ObjectType.RICH_TEXT, exports.ObjectType.IMAGE, exports.ObjectType.RECTANGLE, exports.ObjectType.VERTICAL_RULE, exports.ObjectType.HORIZONTAL_RULE);
313
+ var objects = _(allObjects)
314
+ .partition(function (object) { return object.isPinToBottom(); })
315
+ .value();
316
+ var footerObjects = objects[0];
317
+ var bodyObjects = objects[1];
318
+ var bodyWidth = canvasDimensions.widthPx - canvasMargin.right - canvasMargin.left;
319
+ canvas.redraw();
320
+ //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.
321
+ this.applyWidths(allObjects, bodyWidth);
322
+ var bodyRows = this.getRows(bodyObjects);
323
+ var footerRows = this.getRows(footerObjects);
324
+ var minimumHeight = canvasMargin.top + bodyRows.totalHeight + footerRows.totalHeight + canvasMargin.bottom;
325
+ this.adjustCanvasSize(canvas, minimumHeight);
326
+ this.layoutFooter(footerRows, canvas);
327
+ this.layoutBody(bodyRows, canvas, footerRows.totalHeight);
328
+ };
329
+ StackObjectsLayoutFunction.prototype.layoutFooter = function (footerRows, canvas) {
330
+ var canvasDimensions = canvas.getDimensions();
331
+ var canvasMargin = canvas.getMargin();
332
+ var layoutAreaWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
333
+ var nextObjectTop = canvasDimensions.heightPx - canvasMargin.bottom - footerRows.totalHeight;
334
+ var currentColumnWidthPercent = 0;
335
+ _.each(footerRows.rows, function (row) {
336
+ _.each(row.objects, function (object) {
337
+ var columnOffset = currentColumnWidthPercent / 100 * layoutAreaWidth;
338
+ var objectMargin = tsOptchain.oc(object.getMargin()).left(0);
339
+ var left = canvasMargin.left + columnOffset + objectMargin;
340
+ if (object.getType() === exports.ObjectType.VERTICAL_RULE)
341
+ object.setPosition({ height: row.height });
342
+ object.setPosition({
343
+ top: nextObjectTop + tsOptchain.oc(object.getMargin()).top(0),
344
+ left: left
345
+ });
346
+ currentColumnWidthPercent += object.getColumnWidthPercent();
347
+ });
348
+ currentColumnWidthPercent = 0;
349
+ nextObjectTop += row.height;
350
+ });
351
+ };
352
+ StackObjectsLayoutFunction.prototype.layoutBody = function (bodyRows, canvas, footerHeight) {
353
+ var canvasDimensions = canvas.getDimensions();
354
+ var canvasMargin = canvas.getMargin();
355
+ var workableWidth = canvasDimensions.widthPx - canvasMargin.left - canvasMargin.right;
356
+ var workableHeight = canvasDimensions.heightPx - canvasMargin.top - canvasMargin.bottom - footerHeight;
357
+ var leftoverSpace = workableHeight - bodyRows.totalHeight;
358
+ var spacesRequired = this.countSpaces(bodyRows);
359
+ var spaceSize = leftoverSpace / spacesRequired;
360
+ var nextObjectTop = canvasMargin.top;
361
+ var currentColumnWidthPercent = 0;
362
+ for (var i = 0; i < bodyRows.rows.length; i++) {
363
+ var row = bodyRows.rows[i];
364
+ var nextRow = bodyRows.rows[i + 1];
365
+ for (var _i = 0, _a = row.objects; _i < _a.length; _i++) {
366
+ var object = _a[_i];
367
+ var columnOffset = currentColumnWidthPercent / 100 * workableWidth;
368
+ var objectMargin = tsOptchain.oc(object.getMargin()).left(0);
369
+ var objectLeft = canvasMargin.left + columnOffset + objectMargin;
370
+ if (object.getType() === exports.ObjectType.TEXT && object.isBulleted())
371
+ objectLeft += object.getBulletMargin();
372
+ if (object.getType() === exports.ObjectType.TEXT && object.isOrderedList())
373
+ objectLeft += object.getOrderedListMargin();
374
+ if (object.getType() === exports.ObjectType.VERTICAL_RULE)
375
+ return;
376
+ object.setPosition({
377
+ top: nextObjectTop + tsOptchain.oc(object.getMargin()).top(0),
378
+ left: objectLeft
379
+ });
380
+ currentColumnWidthPercent += object.getColumnWidthPercent();
381
+ }
382
+ currentColumnWidthPercent = 0;
383
+ nextObjectTop += row.height;
384
+ var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
385
+ var nextRowIsHR = tsOptchain.oc(nextRow).objects.length() === 1 && tsOptchain.oc(nextRow).objects()[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
386
+ if (!thisRowIsHR && !nextRowIsHR) {
387
+ nextObjectTop += spaceSize;
388
+ }
389
+ }
390
+ };
391
+ StackObjectsLayoutFunction.prototype.applyWidths = function (objects, layoutWidth) {
392
+ _(objects).forEach(function (object) {
393
+ var targetWidth = object.getColumnWidthPercent() / 100 * layoutWidth;
394
+ var actualWidth = targetWidth - tsOptchain.oc(object.getMargin()).left(0) - tsOptchain.oc(object.getMargin()).right(0);
395
+ if (object.getType() === exports.ObjectType.VERTICAL_RULE)
396
+ return;
397
+ if (object.getType() === exports.ObjectType.TEXT && object.isBulleted())
398
+ actualWidth -= object.getBulletMargin();
399
+ if (object.getType() === exports.ObjectType.TEXT && object.isOrderedList())
400
+ actualWidth -= object.getOrderedListMargin();
401
+ object.setPosition({
402
+ width: actualWidth
403
+ });
404
+ object.updateDimensions();
405
+ });
406
+ };
407
+ StackObjectsLayoutFunction.prototype.adjustCanvasSize = function (canvas, requiredHeight) {
408
+ if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
409
+ return;
410
+ var dimensions = canvas.getDimensions();
411
+ var minHeight = tsOptchain.oc(canvas.getDimensionsRestrictions()).height.min(MIN_MAGNITUDE);
412
+ var targetDimensions = canvas.getDimensions().withSize(dimensions.width, minHeight);
413
+ while (targetDimensions.heightPx < requiredHeight) {
414
+ targetDimensions = targetDimensions.withSize(dimensions.width, targetDimensions.height + 1);
415
+ }
416
+ if (dimensions.height !== targetDimensions.height) {
417
+ canvas.setDimensions(targetDimensions);
418
+ }
419
+ };
420
+ StackObjectsLayoutFunction.prototype.getRows = function (objectsToLayout) {
421
+ var _this = this;
422
+ var result = { totalHeight: 0, rows: [] };
423
+ var currentWidth = 0;
424
+ var row = { objects: [], height: 1 };
425
+ _.each(objectsToLayout, function (object) {
426
+ var nextWidth = object.getColumnWidthPercent();
427
+ var objectHeight = _this.getObjectHeight(object);
428
+ if (currentWidth + nextWidth > 100) {
429
+ result.rows.push(row);
430
+ row = { objects: [], height: 1 };
431
+ currentWidth = 0;
432
+ }
433
+ row.objects.push(object);
434
+ if (object.getType() !== exports.ObjectType.VERTICAL_RULE)
435
+ row.height = Math.max(row.height, objectHeight);
436
+ currentWidth += nextWidth;
437
+ });
438
+ if (row.objects.length)
439
+ result.rows.push(row);
440
+ result.totalHeight = _.reduce(result.rows, function (x, y) { return x + y.height; }, 0);
441
+ return result;
442
+ };
443
+ StackObjectsLayoutFunction.prototype.getObjectHeight = function (element) {
444
+ return element.getBoundingBox().height
445
+ + tsOptchain.oc(element.getMargin()).top(0)
446
+ + tsOptchain.oc(element.getMargin()).bottom(0);
447
+ };
448
+ StackObjectsLayoutFunction.prototype.countSpaces = function (rows) {
449
+ var count = 0;
450
+ for (var i = 0; i < rows.rows.length - 1; i++) {
451
+ var row = rows.rows[i];
452
+ var nextRow = rows.rows[i + 1];
453
+ var thisRowIsHR = row.objects.length === 1 && row.objects[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
454
+ var nextRowIsHR = tsOptchain.oc(nextRow).objects.length() === 1 && tsOptchain.oc(nextRow).objects()[0].getType() === exports.ObjectType.HORIZONTAL_RULE;
455
+ if (!thisRowIsHR && !nextRowIsHR) {
456
+ count++;
457
+ }
458
+ }
459
+ return count;
460
+ };
461
+ return StackObjectsLayoutFunction;
462
+ }());
463
+
464
+ var RepositionBordersLayoutFunction = /** @class */ (function () {
465
+ function RepositionBordersLayoutFunction() {
466
+ }
467
+ RepositionBordersLayoutFunction.prototype.execute = function (canvas) {
468
+ canvas.getObjectsByTypeInternal(exports.ObjectType.BORDER)
469
+ .forEach(function (border) { return border.updatePosition(); });
470
+ };
471
+ return RepositionBordersLayoutFunction;
472
+ }());
473
+
474
+ var RepositionBackgroundsLayoutFunction = /** @class */ (function () {
475
+ function RepositionBackgroundsLayoutFunction() {
476
+ }
477
+ RepositionBackgroundsLayoutFunction.prototype.execute = function (canvas) {
478
+ canvas.getObjectsByTypeInternal(exports.ObjectType.BACKGROUND_IMAGE)
479
+ .forEach(function (border) { return border.updatePosition(); });
480
+ };
481
+ return RepositionBackgroundsLayoutFunction;
482
+ }());
483
+
484
+ var StandardLayoutManager = /** @class */ (function (_super) {
485
+ __extends(StandardLayoutManager, _super);
486
+ function StandardLayoutManager(canvas) {
487
+ var _this = _super.call(this, canvas) || this;
488
+ _this.key = exports.LayoutManager.STANDARD;
489
+ _this.isEnforcedPositioning = true;
490
+ _this.enterTextEditImmediatelyOnSelect = true;
491
+ _this.redrawAll = new RedrawAllLayoutFunction();
492
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
493
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
494
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
495
+ _this.stackObjects = new StackObjectsLayoutFunction();
496
+ _this.updateObjectDimensions = new UpdateObjectDimensionsLayoutFunction();
497
+ return _this;
498
+ }
499
+ /**
500
+ * @override
501
+ */
502
+ StandardLayoutManager.prototype.onInit = function () {
503
+ this.stackAndRedraw();
504
+ };
505
+ /**
506
+ * @override
507
+ */
508
+ StandardLayoutManager.prototype.onProfileChange = function (profile) {
509
+ this.canvas.setMultiSelect(false);
510
+ this.redrawAll.execute(this.canvas);
511
+ };
512
+ /**
513
+ * @override
514
+ */
515
+ StandardLayoutManager.prototype.onCanvasDimensionsChange = function () {
516
+ this.repositionCutoffs.execute(this.canvas);
517
+ this.repositionBorders.execute(this.canvas);
518
+ this.repositionBackgrounds.execute(this.canvas);
519
+ };
520
+ /**
521
+ * @override
522
+ */
523
+ StandardLayoutManager.prototype.onTextChange = function () {
524
+ this.stackAndRedraw();
525
+ };
526
+ /**
527
+ * @override
528
+ */
529
+ StandardLayoutManager.prototype.onObjectListChange = function () {
530
+ this.stackAndRedraw();
531
+ };
532
+ /**
533
+ * @override
534
+ */
535
+ StandardLayoutManager.prototype.onMarginChange = function () {
536
+ this.stackAndRedraw();
537
+ };
538
+ StandardLayoutManager.prototype.stackAndRedraw = function () {
539
+ this.stackObjects.execute(this.canvas);
540
+ this.repositionCutoffs.execute(this.canvas);
541
+ this.repositionBorders.execute(this.canvas);
542
+ this.repositionBackgrounds.execute(this.canvas);
543
+ this.updateObjectDimensions.execute(this.canvas);
544
+ this.redrawAll.execute(this.canvas);
545
+ };
546
+ return StandardLayoutManager;
547
+ }(AbstractLayoutManager));
548
+
549
+ function isMutableBackgroundColor(object) {
550
+ return "setBackgroundColor" in object;
551
+ }
552
+
553
+ function isMutableColor(object) {
554
+ return "setColor" in object;
555
+ }
556
+
557
+ function isMutableImage(object) {
558
+ return "setImageUrl" in object;
559
+ }
560
+
561
+ function isMutablePosition(object) {
562
+ return "centerHorizontally" in object;
563
+ }
564
+
565
+ function isMutableStroke(object) {
566
+ return "setStrokeColor" in object;
567
+ }
568
+
569
+ function isMutableTextStyle(object) {
570
+ return "getTextSelection" in object;
571
+ }
572
+
573
+ function isMutableText(object) {
574
+ return "setText" in object;
575
+ }
576
+
577
+ /**
578
+ * Data for a persisted canvas object.
579
+ */
580
+ var CanvasObjectData = /** @class */ (function () {
581
+ function CanvasObjectData(type, id) {
582
+ this.id = id;
583
+ this.type = type;
584
+ }
585
+ return CanvasObjectData;
586
+ }());
587
+
588
+ var ROTATION_SNAP_ANGLE = 45;
589
+ var AbstractCanvasObject = /** @class */ (function () {
590
+ /**
591
+ * Create a new instance.
592
+ * @param type Object type.
593
+ * @param canvas Interactive canvas that the field will be rendered on.
594
+ * @param fabricObject The fabric object to bind this field to.
595
+ * @param data Existing persisted field data to load from, if applicable.
596
+ */
597
+ function AbstractCanvasObject(type, canvas, fabricObject, data) {
598
+ var _this = this;
599
+ this.canvas = canvas;
600
+ this.fabricObject = fabricObject;
601
+ this.data = data ? data : new CanvasObjectData(type, this.fabricObject.id);
602
+ this.dimensions$ = new rxjs.BehaviorSubject(new FieldDimensions(this.fabricObject, this.canvas));
603
+ this.opacity$ = new rxjs.BehaviorSubject(this.fabricObject.opacity);
604
+ this.updatePinToBottomDistance();
605
+ this.canvas.getProfile$().subscribe(function (profile) { return _this.onProfileChange(profile); });
606
+ this.canvas.getLayoutManager$().subscribe(function (layoutManager) { return _this.onLayoutManagerChange(layoutManager); });
607
+ this.fabricObject.on("moving", function (e) { return _this.onMove(e); });
608
+ this.fabricObject.on("rotating", function (e) { return _this.onRotate(e); });
609
+ this.fabricObject.on("scaling", function (e) { return _this.onScale(e); });
610
+ this.fabricObject.on("scaled", function (e) { return _this.afterScale(e); });
611
+ }
612
+ /**
613
+ * @override
614
+ * @inheritDoc
615
+ */
616
+ AbstractCanvasObject.prototype.getId = function () {
617
+ return this.data.id;
618
+ };
619
+ /**
620
+ * @override
621
+ * @inheritDoc
622
+ */
623
+ AbstractCanvasObject.prototype.getType = function () {
624
+ return this.data.type;
625
+ };
626
+ /**
627
+ * @override
628
+ * @inheritDoc
629
+ */
630
+ AbstractCanvasObject.prototype.getDescription = function () {
631
+ switch (this.data.type) {
632
+ case exports.ObjectType.BORDER:
633
+ return "Border";
634
+ case exports.ObjectType.CUTOFF:
635
+ return "Bottom Border";
636
+ case exports.ObjectType.IMAGE:
637
+ return "Image";
638
+ case exports.ObjectType.LIBRARY_IMAGE:
639
+ return "Library Image";
640
+ case exports.ObjectType.RECTANGLE:
641
+ return "Rectangle";
642
+ case exports.ObjectType.TEXT:
643
+ return "Text";
644
+ default:
645
+ return "Field";
646
+ }
647
+ };
648
+ /**
649
+ * @override
650
+ * @inheritDoc
651
+ */
652
+ AbstractCanvasObject.prototype.setSortCaption = function (value) {
653
+ this.data.sortCaption = value;
654
+ };
655
+ /**
656
+ * @override
657
+ * @inheritDoc
658
+ */
659
+ AbstractCanvasObject.prototype.isSortCaption = function () {
660
+ return this.data.sortCaption;
661
+ };
662
+ /**
663
+ * @override
664
+ * @inheritDoc
665
+ */
666
+ AbstractCanvasObject.prototype.getDimensions = function () {
667
+ return this.dimensions$.value;
668
+ };
669
+ /**
670
+ * @override
671
+ * @inheritDoc
672
+ */
673
+ AbstractCanvasObject.prototype.getDimensions$ = function () {
674
+ return this.dimensions$;
675
+ };
676
+ /**
677
+ * @override
678
+ * @inheritDoc
679
+ */
680
+ AbstractCanvasObject.prototype.getOpacity = function () {
681
+ return this.opacity$.value;
682
+ };
683
+ /**
684
+ * @override
685
+ * @inheritDoc
686
+ */
687
+ AbstractCanvasObject.prototype.getOpacity$ = function () {
688
+ return this.opacity$;
689
+ };
690
+ /**
691
+ * @override
692
+ * @inheritDoc
693
+ */
694
+ AbstractCanvasObject.prototype.setOpacity = function (value) {
695
+ this.fabricObject.set({ opacity: value });
696
+ this.opacity$.next(value);
697
+ this.redraw();
698
+ };
699
+ /**
700
+ * @override
701
+ * @inheritDoc
702
+ */
703
+ AbstractCanvasObject.prototype.getMargin = function () {
704
+ return this.data.margin || {
705
+ top: 0,
706
+ right: 0,
707
+ bottom: 0,
708
+ left: 0
709
+ };
710
+ };
711
+ /**
712
+ * @override
713
+ * @inheritDoc
714
+ */
715
+ AbstractCanvasObject.prototype.setMargin = function (margin) {
716
+ if (!margin)
717
+ return;
718
+ var newMargin = tsOptchain.oc(this.data).margin({
719
+ top: 0,
720
+ right: 0,
721
+ bottom: 0,
722
+ left: 0
723
+ });
724
+ if (margin.top != undefined)
725
+ newMargin.top = margin.top || 0;
726
+ if (margin.right != undefined)
727
+ newMargin.right = margin.right || 0;
728
+ if (margin.bottom != undefined)
729
+ newMargin.bottom = margin.bottom || 0;
730
+ if (margin.left != undefined)
731
+ newMargin.left = margin.left || 0;
732
+ this.data.margin = newMargin;
733
+ this.canvas.notifyObjectListChanged();
734
+ };
735
+ /**
736
+ * @override
737
+ * @inheritDoc
738
+ */
739
+ AbstractCanvasObject.prototype.getColumnWidthPercent = function () {
740
+ return Math.max(Math.min(tsOptchain.oc(this.data).columnWidthPercent(100), 100), 0);
741
+ };
742
+ /**
743
+ * @override
744
+ * @inheritDoc
745
+ */
746
+ AbstractCanvasObject.prototype.setColumnWidthPercent = function (percent) {
747
+ this.data.columnWidthPercent = percent;
748
+ this.canvas.notifyObjectListChanged();
749
+ };
750
+ /**
751
+ * @override
752
+ * @inheritDoc
753
+ */
754
+ AbstractCanvasObject.prototype.bringForward = function () {
755
+ this.fabricObject.bringForward();
756
+ this.canvas.syncObjectList();
757
+ };
758
+ /**
759
+ * @override
760
+ * @inheritDoc
761
+ */
762
+ AbstractCanvasObject.prototype.bringToFront = function () {
763
+ this.fabricObject.bringToFront();
764
+ this.canvas.syncObjectList();
765
+ };
766
+ /**
767
+ * @override
768
+ * @inheritDoc
769
+ */
770
+ AbstractCanvasObject.prototype.sendBackward = function () {
771
+ this.fabricObject.sendBackwards();
772
+ this.canvas.syncObjectList();
773
+ };
774
+ /**
775
+ * @override
776
+ * @inheritDoc
777
+ */
778
+ AbstractCanvasObject.prototype.sendToBack = function () {
779
+ this.fabricObject.sendToBack();
780
+ this.canvas.syncObjectList();
781
+ };
782
+ /**
783
+ * @override
784
+ * @inheritDoc
785
+ */
786
+ AbstractCanvasObject.prototype.moveUp = function () {
787
+ this.sendBackward();
788
+ };
789
+ /**
790
+ * @override
791
+ * @inheritDoc
792
+ */
793
+ AbstractCanvasObject.prototype.moveDown = function () {
794
+ this.bringForward();
795
+ };
796
+ /**
797
+ * @override
798
+ * @inheritDoc
799
+ */
800
+ AbstractCanvasObject.prototype.delete = function () {
801
+ this.canvas.removeObject(this);
802
+ this.onDelete();
803
+ };
804
+ /**
805
+ * @override
806
+ * @inheritDoc
807
+ */
808
+ AbstractCanvasObject.prototype.persist = function () {
809
+ return _.clone(this.data);
810
+ };
811
+ /**
812
+ * @override
813
+ * @inheritDoc
814
+ */
815
+ AbstractCanvasObject.prototype.isPinToBottom = function () {
816
+ return this.data.pinToBottom;
817
+ };
818
+ /**
819
+ * @override
820
+ * @inheritDoc
821
+ */
822
+ AbstractCanvasObject.prototype.setPinToBottom = function (value) {
823
+ if (value === void 0) { value = true; }
824
+ this.updatePinToBottomDistance();
825
+ this.data.pinToBottom = value;
826
+ this.canvas.notifyObjectListChanged();
827
+ this.updateFabricObjectBehavior();
828
+ };
829
+ /**
830
+ * @override
831
+ * @inheritDoc
832
+ */
833
+ AbstractCanvasObject.prototype.setLeft = function (left) {
834
+ this.setPosition({ left: left });
835
+ };
836
+ /**
837
+ * @override
838
+ * @inheritDoc
839
+ */
840
+ AbstractCanvasObject.prototype.setTop = function (top) {
841
+ this.setPosition({ top: top });
842
+ };
843
+ /**
844
+ * @override
845
+ * @inheritDoc
846
+ */
847
+ AbstractCanvasObject.prototype.setHeight = function (height) {
848
+ this.setPosition({ height: height });
849
+ };
850
+ /**
851
+ * @override
852
+ * @inheritDoc
853
+ */
854
+ AbstractCanvasObject.prototype.setWidth = function (width) {
855
+ this.setPosition({ width: width });
856
+ };
857
+ /**
858
+ * @override
859
+ * @inheritDoc
860
+ */
861
+ AbstractCanvasObject.prototype.setAngle = function (angle) {
862
+ this.setPosition({ angle: angle });
863
+ };
864
+ /**
865
+ * @override
866
+ * @inheritDoc
867
+ */
868
+ AbstractCanvasObject.prototype.setScaleX = function (scale) {
869
+ this.setPosition({ scaleX: scale });
870
+ };
871
+ /**
872
+ * @override
873
+ * @inheritDoc
874
+ */
875
+ AbstractCanvasObject.prototype.setScaleY = function (scale) {
876
+ this.setPosition({ scaleY: scale });
877
+ };
878
+ /**
879
+ * Get the underlying fabric object.
880
+ * (Internal use only, do not expose this outside the canvas module).
881
+ */
882
+ AbstractCanvasObject.prototype.getFabricObjectInternal = function () {
883
+ return this.fabricObject;
884
+ };
885
+ AbstractCanvasObject.prototype.setPosition = function (position) {
886
+ var scale = this.getDimensions().scale;
887
+ if (position.top != undefined)
888
+ this.fabricObject.set({ top: position.top });
889
+ if (position.left != undefined)
890
+ this.fabricObject.set({ left: position.left });
891
+ if (position.width != undefined)
892
+ this.fabricObject.set({ width: position.width / scale.x });
893
+ if (position.height != undefined)
894
+ this.fabricObject.set({ height: position.height / scale.y });
895
+ if (position.angle != undefined)
896
+ this.fabricObject.set({ angle: position.angle });
897
+ if (position.scaleX != undefined)
898
+ this.fabricObject.set({ scaleX: position.scaleX });
899
+ if (position.scaleY != undefined)
900
+ this.fabricObject.set({ scaleY: position.scaleY });
901
+ this.setCoords();
902
+ this.redraw();
903
+ };
904
+ AbstractCanvasObject.prototype.setCoords = function () {
905
+ this.fabricObject.setCoords();
906
+ };
907
+ AbstractCanvasObject.prototype.updateDimensions = function () {
908
+ this.setCoords();
909
+ var dimensions = new FieldDimensions(this.fabricObject, this.canvas);
910
+ this.dimensions$.next(dimensions);
911
+ };
912
+ AbstractCanvasObject.prototype.getBoundingBox = function () {
913
+ var absolute = true;
914
+ var calculate = true;
915
+ return this.fabricObject.getBoundingRect(absolute, calculate);
916
+ };
917
+ AbstractCanvasObject.prototype.moveToPinnedPosition = function () {
918
+ if (this.data.pinToBottom) {
919
+ this.setPosition({
920
+ top: this.canvas.getDimensions().heightPx - this.pinToBottomDistance
921
+ });
922
+ }
923
+ };
924
+ AbstractCanvasObject.prototype.updatePinToBottomDistance = function () {
925
+ this.pinToBottomDistance = this.canvas.getDimensions().heightPx - this.getDimensions().top.px;
926
+ };
927
+ AbstractCanvasObject.prototype.redraw = function () {
928
+ this.canvas.redraw();
929
+ };
930
+ // noinspection JSUnusedLocalSymbols
931
+ AbstractCanvasObject.prototype.onProfileChange = function (profile) {
932
+ this.updateFabricObjectBehavior();
933
+ this.redraw();
934
+ };
935
+ // noinspection JSUnusedLocalSymbols
936
+ AbstractCanvasObject.prototype.onLayoutManagerChange = function (layoutManager) {
937
+ this.updateFabricObjectBehavior();
938
+ this.redraw();
939
+ };
940
+ // noinspection JSUnusedLocalSymbols
941
+ AbstractCanvasObject.prototype.onMove = function (event) {
942
+ if (!this.canvas.getProfile().allowObjectsToLeaveCanvas) {
943
+ this.preventLeavingCanvas();
944
+ }
945
+ this.updateDimensions();
946
+ };
947
+ AbstractCanvasObject.prototype.onRotate = function (event) {
948
+ if (event.e.shiftKey) {
949
+ this.fabricObject.set({ snapAngle: 0 });
950
+ }
951
+ else {
952
+ this.fabricObject.set({ snapAngle: ROTATION_SNAP_ANGLE });
953
+ }
954
+ this.updateDimensions();
955
+ };
956
+ // noinspection JSUnusedLocalSymbols
957
+ AbstractCanvasObject.prototype.onScale = function (event) {
958
+ this.updateDimensions();
959
+ };
960
+ // noinspection JSUnusedLocalSymbols
961
+ AbstractCanvasObject.prototype.afterScale = function (event) {
962
+ this.updateDimensions();
963
+ };
964
+ AbstractCanvasObject.prototype.onDelete = function () {
965
+ //no-op
966
+ };
967
+ AbstractCanvasObject.prototype.preventLeavingCanvas = function () {
968
+ var overflow = this.getCanvasOverflow();
969
+ if (overflow.hasOverflow) {
970
+ var adjustX = overflow.left || -overflow.right;
971
+ var adjustY = overflow.top || -overflow.bottom;
972
+ this.fabricObject.set({
973
+ top: this.fabricObject.top + adjustY,
974
+ left: this.fabricObject.left + adjustX
975
+ });
976
+ this.redraw();
977
+ }
978
+ };
979
+ AbstractCanvasObject.prototype.getCanvasOverflow = function () {
980
+ var bound = this.getBoundingBox();
981
+ var canvasDimensions = this.canvas.getDimensions();
982
+ var top = Math.max(0, 0 - bound.top);
983
+ var right = Math.max(0, bound.left + bound.width - canvasDimensions.widthPx);
984
+ var bottom = Math.max(0, bound.top + bound.height - canvasDimensions.heightPx);
985
+ var left = Math.max(0, 0 - bound.left);
986
+ return {
987
+ top: top,
988
+ right: right,
989
+ bottom: bottom,
990
+ left: left,
991
+ hasOverflow: top > 0 || right > 0 || bottom > 0 || left > 0
992
+ };
993
+ };
994
+ AbstractCanvasObject.prototype.centerHorizontallyInternal = function () {
995
+ var canvasWidth = this.canvas.getDimensions().widthPx;
996
+ var objectWidth = this.getDimensions().width.px;
997
+ this.fabricObject.set({ left: ((canvasWidth - objectWidth) / 2) - 0.5 });
998
+ this.updateDimensions();
999
+ this.redraw();
1000
+ };
1001
+ AbstractCanvasObject.prototype.centerVerticallyInternal = function () {
1002
+ var canvasHeight = this.canvas.getDimensions().heightPx;
1003
+ var objectHeight = this.getDimensions().height.px;
1004
+ this.fabricObject.set({ top: ((canvasHeight - objectHeight) / 2) - 0.5 });
1005
+ this.redraw();
1006
+ this.updateDimensions();
1007
+ };
1008
+ AbstractCanvasObject.prototype.nudgeInternal = function (x, y) {
1009
+ if (x === void 0) { x = 0; }
1010
+ if (y === void 0) { y = 0; }
1011
+ this.fabricObject.set({
1012
+ top: this.getDimensions().top.px + y,
1013
+ left: this.getDimensions().left.px + x
1014
+ });
1015
+ this.redraw();
1016
+ this.updateDimensions();
1017
+ };
1018
+ AbstractCanvasObject.prototype.updateFabricObjectBehavior = function () {
1019
+ var allowManualPositioning = !this.canvas.getLayoutManager().isEnforcedPositioning;
1020
+ var profile = this.canvas.getProfile();
1021
+ var options = {
1022
+ allowMove: allowManualPositioning && profile.allowMove && !this.isPinToBottom(),
1023
+ allowRotate: allowManualPositioning && profile.allowRotate && !this.isPinToBottom(),
1024
+ allowScale: allowManualPositioning && profile.allowScale && !this.isPinToBottom()
1025
+ };
1026
+ this.fabricObject.set({
1027
+ lockMovementX: !options.allowMove,
1028
+ lockMovementY: !options.allowMove,
1029
+ lockScalingX: !options.allowScale,
1030
+ lockScalingY: !options.allowScale,
1031
+ lockScalingFlip: true,
1032
+ lockRotation: !options.allowRotate
1033
+ });
1034
+ this.fabricObject.setControlsVisibility({
1035
+ tl: options.allowScale,
1036
+ tr: options.allowScale,
1037
+ br: options.allowScale,
1038
+ bl: options.allowScale,
1039
+ ml: options.allowScale,
1040
+ mt: options.allowScale,
1041
+ mr: options.allowScale,
1042
+ mb: options.allowScale,
1043
+ mtr: options.allowRotate
1044
+ });
1045
+ };
1046
+ return AbstractCanvasObject;
1047
+ }());
1048
+ var FieldDimensions = /** @class */ (function () {
1049
+ function FieldDimensions(fabricObject, canvas) {
1050
+ var widthPxToMmFunction = canvas.getDimensions().widthPxToMm;
1051
+ var heightPxToMmFunction = canvas.getDimensions().heightPxToMm;
1052
+ this.top = { px: fabricObject.top, mm: heightPxToMmFunction(fabricObject.top) };
1053
+ this.left = { px: fabricObject.left, mm: widthPxToMmFunction(fabricObject.left) };
1054
+ var widthPx = fabricObject.width * fabricObject.scaleX;
1055
+ var heightPx = fabricObject.height * fabricObject.scaleY;
1056
+ this.width = { px: widthPx, mm: widthPxToMmFunction(widthPx) };
1057
+ this.height = { px: heightPx, mm: heightPxToMmFunction(heightPx) };
1058
+ this.scale = { x: fabricObject.scaleX, y: fabricObject.scaleY };
1059
+ this.angle = fabricObject.angle;
1060
+ }
1061
+ return FieldDimensions;
1062
+ }());
1063
+
1064
+ var BackgroundImage = /** @class */ (function (_super) {
1065
+ __extends(BackgroundImage, _super);
1066
+ function BackgroundImage(canvas, fabricObject, persistedField) {
1067
+ var _this = _super.call(this, exports.ObjectType.BACKGROUND_IMAGE, canvas, fabricObject, persistedField) || this;
1068
+ _this.imageUrl$ = new rxjs.BehaviorSubject(_this.fabricObject.getSrc());
1069
+ _this.data.imagePath = _this.imageUrl$.value;
1070
+ _this.updatePosition();
1071
+ return _this;
1072
+ }
1073
+ BackgroundImage.prototype.updatePosition = function () {
1074
+ var _a = this.canvas.getDimensions(), widthPx = _a.widthPx, heightPx = _a.heightPx;
1075
+ this.fabricObject.set({
1076
+ top: 0,
1077
+ left: 0,
1078
+ scaleX: widthPx / this.fabricObject.width,
1079
+ scaleY: heightPx / this.fabricObject.height
1080
+ });
1081
+ this.fabricObject.sendToBack();
1082
+ this.updateDimensions();
1083
+ };
1084
+ /**
1085
+ * @override
1086
+ * @inheritDoc
1087
+ */
1088
+ BackgroundImage.prototype.updateFabricObjectBehavior = function () {
1089
+ _super.prototype.updateFabricObjectBehavior.call(this);
1090
+ this.fabricObject.set({
1091
+ lockMovementX: true,
1092
+ lockMovementY: true,
1093
+ lockScalingX: true,
1094
+ lockScalingY: true,
1095
+ lockScalingFlip: true
1096
+ });
1097
+ this.fabricObject.setControlsVisibility({
1098
+ tl: false,
1099
+ tr: false,
1100
+ br: false,
1101
+ bl: false,
1102
+ ml: false,
1103
+ mt: false,
1104
+ mr: false,
1105
+ mb: false,
1106
+ mtr: false
1107
+ });
1108
+ this.redraw();
1109
+ };
1110
+ /**
1111
+ * @override
1112
+ * @inheritDoc
1113
+ */
1114
+ BackgroundImage.prototype.getImageUrl = function () {
1115
+ return this.imageUrl$.value;
1116
+ };
1117
+ /**
1118
+ * @override
1119
+ * @inheritDoc
1120
+ */
1121
+ BackgroundImage.prototype.getImageUrl$ = function () {
1122
+ return this.imageUrl$;
1123
+ };
1124
+ /**
1125
+ * @override
1126
+ * @inheritDoc
1127
+ */
1128
+ BackgroundImage.prototype.setImageUrl = function (url) {
1129
+ return __awaiter(this, void 0, void 0, function () {
1130
+ return __generator(this, function (_a) {
1131
+ switch (_a.label) {
1132
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1133
+ case 1:
1134
+ _a.sent();
1135
+ this.data.imagePath = url;
1136
+ this.imageUrl$.next(url);
1137
+ this.canvas.notifyObjectListChanged();
1138
+ return [2 /*return*/];
1139
+ }
1140
+ });
1141
+ });
1142
+ };
1143
+ /**
1144
+ * @override
1145
+ * @inheritDoc
1146
+ */
1147
+ BackgroundImage.prototype.setImageWidth = function (px, sizeRestrictions) {
1148
+ return 0; //no-op
1149
+ };
1150
+ BackgroundImage.prototype.setCanvasImage = function (url) {
1151
+ return __awaiter(this, void 0, void 0, function () {
1152
+ var imageOptions, _a, widthPx, heightPx;
1153
+ var _this = this;
1154
+ return __generator(this, function (_b) {
1155
+ switch (_b.label) {
1156
+ case 0:
1157
+ imageOptions = { crossOrigin: "anonymous" };
1158
+ _a = this.canvas.getDimensions(), widthPx = _a.widthPx, heightPx = _a.heightPx;
1159
+ return [4 /*yield*/, new Promise(function (resolve) {
1160
+ _this.fabricObject.setSrc(url, function (img) {
1161
+ img.scaleToWidth(widthPx);
1162
+ img.scaleToHeight(heightPx);
1163
+ img.setCoords();
1164
+ _this.redraw();
1165
+ resolve();
1166
+ }, imageOptions);
1167
+ })];
1168
+ case 1: return [2 /*return*/, _b.sent()];
1169
+ }
1170
+ });
1171
+ });
1172
+ };
1173
+ return BackgroundImage;
1174
+ }(AbstractCanvasObject));
1175
+
1176
+ var Border = /** @class */ (function (_super) {
1177
+ __extends(Border, _super);
1178
+ function Border(canvas, fabricObject, persistedField) {
1179
+ var _this = _super.call(this, exports.ObjectType.BORDER, canvas, fabricObject, persistedField) || this;
1180
+ _this.strokeWidth$ = new rxjs.BehaviorSubject(0);
1181
+ _this.canvas = canvas;
1182
+ _this.strokeWidth$.next(_this.fabricObject.strokeWidth);
1183
+ _this.fabricObject.set({ "fill": null });
1184
+ _this.updatePosition();
1185
+ return _this;
1186
+ }
1187
+ /**
1188
+ * @override
1189
+ * @inheritDoc
1190
+ */
1191
+ Border.prototype.getColor = function () {
1192
+ return this.fabricObject.stroke;
1193
+ };
1194
+ /**
1195
+ * @override
1196
+ * @inheritDoc
1197
+ */
1198
+ Border.prototype.setColor = function (color) {
1199
+ this.fabricObject.set({ stroke: color });
1200
+ this.data.color = color;
1201
+ this.redraw();
1202
+ };
1203
+ /**
1204
+ * @override
1205
+ * @inheritDoc
1206
+ */
1207
+ Border.prototype.getStrokeWidth = function () {
1208
+ return this.fabricObject.strokeWidth;
1209
+ };
1210
+ /**
1211
+ * @override
1212
+ * @inheritDoc
1213
+ */
1214
+ Border.prototype.getStrokeWidth$ = function () {
1215
+ return this.strokeWidth$;
1216
+ };
1217
+ /**
1218
+ * @override
1219
+ * @inheritDoc
1220
+ */
1221
+ Border.prototype.setStrokeWidth = function (width) {
1222
+ this.strokeWidth$.next(width);
1223
+ this.data.strokeWidth = width;
1224
+ this.updatePosition();
1225
+ this.canvas.notifyMarginChanged();
1226
+ this.redraw();
1227
+ };
1228
+ Border.prototype.getPadding = function () {
1229
+ return this.data.padding || {
1230
+ top: 0,
1231
+ right: 0,
1232
+ bottom: 0,
1233
+ left: 0
1234
+ };
1235
+ };
1236
+ Border.prototype.setPadding = function (padding) {
1237
+ if (!padding)
1238
+ return;
1239
+ this.data.padding = {
1240
+ top: padding.top || 0,
1241
+ right: padding.right || 0,
1242
+ bottom: padding.bottom || 0,
1243
+ left: padding.left || 0
1244
+ };
1245
+ this.canvas.notifyMarginChanged();
1246
+ this.redraw();
1247
+ };
1248
+ Border.prototype.updatePosition = function () {
1249
+ this.fabricObject.set({
1250
+ strokeWidth: this.strokeWidth$.value,
1251
+ top: 0,
1252
+ left: 0,
1253
+ width: this.canvas.getDimensions().widthPx - this.strokeWidth$.value,
1254
+ height: this.canvas.getDimensions().heightPx - this.strokeWidth$.value
1255
+ });
1256
+ };
1257
+ /**
1258
+ * @override
1259
+ * @inheritDoc
1260
+ */
1261
+ Border.prototype.updateFabricObjectBehavior = function () {
1262
+ _super.prototype.updateFabricObjectBehavior.call(this);
1263
+ this.fabricObject.set({
1264
+ lockMovementX: true,
1265
+ lockMovementY: true,
1266
+ lockScalingX: true,
1267
+ lockScalingY: true,
1268
+ lockScalingFlip: true
1269
+ });
1270
+ this.fabricObject.setControlsVisibility({
1271
+ tl: false,
1272
+ tr: false,
1273
+ br: false,
1274
+ bl: false,
1275
+ ml: false,
1276
+ mt: false,
1277
+ mr: false,
1278
+ mb: false,
1279
+ mtr: false
1280
+ });
1281
+ this.redraw();
1282
+ };
1283
+ return Border;
1284
+ }(AbstractCanvasObject));
1285
+
1286
+ var Cutoff = /** @class */ (function (_super) {
1287
+ __extends(Cutoff, _super);
1288
+ function Cutoff(canvas, fabricObject, persistedField) {
1289
+ var _this = _super.call(this, exports.ObjectType.CUTOFF, canvas, fabricObject, persistedField) || this;
1290
+ _this.strokeWidth$ = new rxjs.BehaviorSubject(0);
1291
+ _this.canvas = canvas;
1292
+ _this.strokeWidth$.next(_this.fabricObject.height);
1293
+ _this.updatePosition();
1294
+ _this.fabricObject.set({ strokeWidth: 0 });
1295
+ return _this;
1296
+ }
1297
+ /**
1298
+ * @override
1299
+ * @inheritDoc
1300
+ */
1301
+ Cutoff.prototype.getColor = function () {
1302
+ return this.fabricObject.fill;
1303
+ };
1304
+ /**
1305
+ * @override
1306
+ * @inheritDoc
1307
+ */
1308
+ Cutoff.prototype.setColor = function (color) {
1309
+ this.fabricObject.set({ fill: color, stroke: color });
1310
+ this.data.color = color;
1311
+ this.redraw();
1312
+ };
1313
+ /**
1314
+ * @override
1315
+ * @inheritDoc
1316
+ */
1317
+ Cutoff.prototype.getStrokeWidth = function () {
1318
+ // noinspection JSSuspiciousNameCombination
1319
+ return this.fabricObject.height;
1320
+ };
1321
+ /**
1322
+ * @override
1323
+ * @inheritDoc
1324
+ */
1325
+ Cutoff.prototype.getStrokeWidth$ = function () {
1326
+ return this.strokeWidth$;
1327
+ };
1328
+ /**
1329
+ * @override
1330
+ * @inheritDoc
1331
+ */
1332
+ Cutoff.prototype.setStrokeWidth = function (width) {
1333
+ this.strokeWidth$.next(width);
1334
+ this.data.strokeWidth = width;
1335
+ this.updatePosition();
1336
+ this.canvas.notifyMarginChanged();
1337
+ this.redraw();
1338
+ };
1339
+ Cutoff.prototype.updatePosition = function () {
1340
+ this.fabricObject.set({
1341
+ top: this.canvas.getDimensions().heightPx - this.strokeWidth$.value,
1342
+ left: 0,
1343
+ width: this.canvas.getDimensions().widthPx,
1344
+ height: this.strokeWidth$.value
1345
+ });
1346
+ };
1347
+ /**
1348
+ * @override
1349
+ * @inheritDoc
1350
+ */
1351
+ Cutoff.prototype.updateFabricObjectBehavior = function () {
1352
+ this.fabricObject.set({
1353
+ lockMovementX: true,
1354
+ lockMovementY: true,
1355
+ lockScalingX: true,
1356
+ lockScalingY: true,
1357
+ lockScalingFlip: true
1358
+ });
1359
+ this.fabricObject.setControlsVisibility({
1360
+ tl: false,
1361
+ tr: false,
1362
+ br: false,
1363
+ bl: false,
1364
+ ml: false,
1365
+ mt: false,
1366
+ mr: false,
1367
+ mb: false,
1368
+ mtr: false
1369
+ });
1370
+ this.redraw();
1371
+ };
1372
+ return Cutoff;
1373
+ }(AbstractCanvasObject));
1374
+
1375
+ var HorizontalRule = /** @class */ (function (_super) {
1376
+ __extends(HorizontalRule, _super);
1377
+ function HorizontalRule(canvas, fabricObject, persistedField) {
1378
+ var _this = _super.call(this, exports.ObjectType.HORIZONTAL_RULE, canvas, fabricObject, persistedField) || this;
1379
+ _this.strokeWidth$ = new rxjs.BehaviorSubject(2);
1380
+ _this.canvas = canvas;
1381
+ _this.strokeWidth$.next(_this.getDimensions().height.px);
1382
+ _this.fabricObject.set({ strokeWidth: 0 });
1383
+ return _this;
1384
+ }
1385
+ /**
1386
+ * @override
1387
+ * @inheritDoc
1388
+ */
1389
+ HorizontalRule.prototype.getStrokeWidth = function () {
1390
+ // noinspection JSSuspiciousNameCombination
1391
+ return this.fabricObject.height;
1392
+ };
1393
+ /**
1394
+ * @override
1395
+ * @inheritDoc
1396
+ */
1397
+ HorizontalRule.prototype.getStrokeWidth$ = function () {
1398
+ return this.strokeWidth$;
1399
+ };
1400
+ /**
1401
+ * @override
1402
+ * @inheritDoc
1403
+ */
1404
+ HorizontalRule.prototype.setStrokeWidth = function (value) {
1405
+ this.strokeWidth$.next(value);
1406
+ this.data.strokeWidth = value;
1407
+ this.setPosition({ height: value });
1408
+ this.canvas.notifyObjectListChanged();
1409
+ this.redraw();
1410
+ };
1411
+ /**
1412
+ * @override
1413
+ * @inheritDoc
1414
+ */
1415
+ HorizontalRule.prototype.getColor = function () {
1416
+ return this.fabricObject.fill;
1417
+ };
1418
+ /**
1419
+ * @override
1420
+ * @inheritDoc
1421
+ */
1422
+ HorizontalRule.prototype.setColor = function (color) {
1423
+ this.fabricObject.set({ fill: color, stroke: color });
1424
+ this.data.color = color;
1425
+ this.redraw();
1426
+ };
1427
+ /**
1428
+ * @override
1429
+ * @inheritDoc
1430
+ */
1431
+ HorizontalRule.prototype.centerHorizontally = function () {
1432
+ _super.prototype.centerHorizontallyInternal.call(this);
1433
+ };
1434
+ /**
1435
+ * @override
1436
+ * @inheritDoc
1437
+ */
1438
+ HorizontalRule.prototype.centerVertically = function () {
1439
+ _super.prototype.centerVerticallyInternal.call(this);
1440
+ };
1441
+ /**
1442
+ * @override
1443
+ * @inheritDoc
1444
+ */
1445
+ HorizontalRule.prototype.nudgeUp = function () {
1446
+ _super.prototype.nudgeInternal.call(this, 0, -1);
1447
+ };
1448
+ /**
1449
+ * @override
1450
+ * @inheritDoc
1451
+ */
1452
+ HorizontalRule.prototype.nudgeDown = function () {
1453
+ _super.prototype.nudgeInternal.call(this, 0, +1);
1454
+ };
1455
+ /**
1456
+ * @override
1457
+ * @inheritDoc
1458
+ */
1459
+ HorizontalRule.prototype.nudgeLeft = function () {
1460
+ _super.prototype.nudgeInternal.call(this, -1, 0);
1461
+ };
1462
+ /**
1463
+ * @override
1464
+ * @inheritDoc
1465
+ */
1466
+ HorizontalRule.prototype.nudgeRight = function () {
1467
+ _super.prototype.nudgeInternal.call(this, +1, 0);
1468
+ };
1469
+ return HorizontalRule;
1470
+ }(AbstractCanvasObject));
1471
+
1472
+ var Image = /** @class */ (function (_super) {
1473
+ __extends(Image, _super);
1474
+ function Image(canvas, fabricObject, persistedField) {
1475
+ var _this = _super.call(this, exports.ObjectType.IMAGE, canvas, fabricObject, persistedField) || this;
1476
+ _this.DEFAULT_RESTRICTIONS = {
1477
+ minWidth: 1,
1478
+ minHeight: 1
1479
+ };
1480
+ _this.canvas = canvas;
1481
+ _this.imageUrl$ = new rxjs.BehaviorSubject(_this.fabricObject.getSrc());
1482
+ _this.data.imagePath = _this.imageUrl$.value;
1483
+ _this.layoutWidth = _this.getBoundingBox().width;
1484
+ return _this;
1485
+ }
1486
+ /**
1487
+ * @override
1488
+ * @inheritDoc
1489
+ */
1490
+ Image.prototype.getImageUrl = function () {
1491
+ return this.imageUrl$.value;
1492
+ };
1493
+ /**
1494
+ * @override
1495
+ * @inheritDoc
1496
+ */
1497
+ Image.prototype.getImageUrl$ = function () {
1498
+ return this.imageUrl$;
1499
+ };
1500
+ /**
1501
+ * @override
1502
+ * @inheritDoc
1503
+ */
1504
+ Image.prototype.setImageUrl = function (url) {
1505
+ return __awaiter(this, void 0, void 0, function () {
1506
+ return __generator(this, function (_a) {
1507
+ switch (_a.label) {
1508
+ case 0: return [4 /*yield*/, this.setCanvasImage(url)];
1509
+ case 1:
1510
+ _a.sent();
1511
+ this.data.imagePath = url;
1512
+ this.imageUrl$.next(url);
1513
+ this.canvas.notifyObjectListChanged();
1514
+ return [2 /*return*/];
1515
+ }
1516
+ });
1517
+ });
1518
+ };
1519
+ /**
1520
+ * @override
1521
+ * @inheritDoc
1522
+ */
1523
+ Image.prototype.setImageWidth = function (px, sizeRestrictions) {
1524
+ if (sizeRestrictions === void 0) { sizeRestrictions = this.DEFAULT_RESTRICTIONS; }
1525
+ var minWidth = Math.max(sizeRestrictions.minWidth, this.getMinWidthBasedOnMinHeight(sizeRestrictions.minHeight));
1526
+ var maxWidth = Math.min(sizeRestrictions.maxWidth, this.getMaxWidthBasedOnMaxHeight(sizeRestrictions.maxHeight));
1527
+ if (px < minWidth) {
1528
+ px = minWidth;
1529
+ }
1530
+ else if (px > maxWidth) {
1531
+ px = maxWidth;
1532
+ }
1533
+ var premultipliedWidth = this.fabricObject.width;
1534
+ var newScale = (premultipliedWidth > 0) ? px / premultipliedWidth : 1;
1535
+ this.fabricObject.set({ scaleX: newScale, scaleY: newScale });
1536
+ this.setCoords();
1537
+ this.canvas.notifyObjectListChanged();
1538
+ return px;
1539
+ };
1540
+ /**
1541
+ * @override
1542
+ * @inheritDoc
1543
+ */
1544
+ Image.prototype.centerHorizontally = function () {
1545
+ _super.prototype.centerHorizontallyInternal.call(this);
1546
+ };
1547
+ /**
1548
+ * @override
1549
+ * @inheritDoc
1550
+ */
1551
+ Image.prototype.centerVertically = function () {
1552
+ _super.prototype.centerVerticallyInternal.call(this);
1553
+ };
1554
+ /**
1555
+ * @override
1556
+ * @inheritDoc
1557
+ */
1558
+ Image.prototype.nudgeUp = function () {
1559
+ _super.prototype.nudgeInternal.call(this, 0, -1);
1560
+ };
1561
+ /**
1562
+ * @override
1563
+ * @inheritDoc
1564
+ */
1565
+ Image.prototype.nudgeDown = function () {
1566
+ _super.prototype.nudgeInternal.call(this, 0, +1);
1567
+ };
1568
+ /**
1569
+ * @override
1570
+ * @inheritDoc
1571
+ */
1572
+ Image.prototype.nudgeLeft = function () {
1573
+ _super.prototype.nudgeInternal.call(this, -1, 0);
1574
+ };
1575
+ /**
1576
+ * @override
1577
+ * @inheritDoc
1578
+ */
1579
+ Image.prototype.nudgeRight = function () {
1580
+ _super.prototype.nudgeInternal.call(this, +1, 0);
1581
+ };
1582
+ /**
1583
+ * @override
1584
+ * @inheritDoc
1585
+ */
1586
+ Image.prototype.setPosition = function (position) {
1587
+ if (this.canvas.getLayoutManager().isEnforcedPositioning) {
1588
+ if (position.top != undefined)
1589
+ this.fabricObject.set({ top: position.top });
1590
+ if (position.width != undefined) {
1591
+ this.layoutWidth = position.width;
1592
+ }
1593
+ if (position.height != undefined) {
1594
+ var premultipliedHeight = this.fabricObject.height;
1595
+ var newScale = position.height / premultipliedHeight;
1596
+ this.fabricObject.set({ scaleX: newScale, scaleY: newScale });
1597
+ this.setCoords();
1598
+ }
1599
+ if (position.left != undefined || position.width != undefined || position.height != undefined) {
1600
+ this.centerHorizontallyInLayoutWidth(position.left || 0);
1601
+ }
1602
+ }
1603
+ else {
1604
+ _super.prototype.setPosition.call(this, position);
1605
+ }
1606
+ };
1607
+ Image.prototype.centerHorizontallyInLayoutWidth = function (left) {
1608
+ var imageWidth = this.getBoundingBox().width;
1609
+ this.fabricObject.set({ left: left + (this.layoutWidth / 2) - (imageWidth / 2) });
1610
+ };
1611
+ Image.prototype.setCanvasImage = function (url) {
1612
+ return __awaiter(this, void 0, void 0, function () {
1613
+ var imageOptions, maxSizeScale, maxWidth;
1614
+ var _this = this;
1615
+ return __generator(this, function (_a) {
1616
+ switch (_a.label) {
1617
+ case 0:
1618
+ imageOptions = { crossOrigin: "anonymous" };
1619
+ maxSizeScale = 2;
1620
+ maxWidth = this.canvas.getDimensions().widthPx / maxSizeScale;
1621
+ return [4 /*yield*/, new Promise(function (resolve) {
1622
+ _this.fabricObject.setSrc(url, function (img) {
1623
+ var newScale = 1;
1624
+ var curWidth = newScale * img.width;
1625
+ if (curWidth > maxWidth) {
1626
+ newScale = maxWidth / curWidth;
1627
+ }
1628
+ img.set({
1629
+ scaleX: newScale,
1630
+ scaleY: newScale
1631
+ });
1632
+ img.setCoords();
1633
+ _this.redraw();
1634
+ resolve();
1635
+ }, imageOptions);
1636
+ })];
1637
+ case 1: return [2 /*return*/, _a.sent()];
1638
+ }
1639
+ });
1640
+ });
1641
+ };
1642
+ Image.prototype.getMinWidthBasedOnMinHeight = function (minHeight) {
1643
+ if (!minHeight) {
1644
+ return 0;
1645
+ }
1646
+ var premultipliedHeight = this.fabricObject.height;
1647
+ var newScale = minHeight / premultipliedHeight;
1648
+ return this.getBoundingBox().width * newScale;
1649
+ };
1650
+ Image.prototype.getMaxWidthBasedOnMaxHeight = function (maxHeight) {
1651
+ if (!maxHeight) {
1652
+ return Infinity;
1653
+ }
1654
+ var premultipliedHeight = this.fabricObject.height;
1655
+ var newScale = maxHeight / premultipliedHeight;
1656
+ return this.getBoundingBox().width * newScale;
1657
+ };
1658
+ return Image;
1659
+ }(AbstractCanvasObject));
1660
+
1661
+ var Rectangle = /** @class */ (function (_super) {
1662
+ __extends(Rectangle, _super);
1663
+ function Rectangle(canvas, fabricObject, persistedField) {
1664
+ var _this = _super.call(this, exports.ObjectType.RECTANGLE, canvas, fabricObject, persistedField) || this;
1665
+ _this.canvas = canvas;
1666
+ return _this;
1667
+ }
1668
+ /**
1669
+ * @override
1670
+ * @inheritDoc
1671
+ */
1672
+ Rectangle.prototype.getColor = function () {
1673
+ return this.fabricObject.fill;
1674
+ };
1675
+ /**
1676
+ * @override
1677
+ * @inheritDoc
1678
+ */
1679
+ Rectangle.prototype.setColor = function (color) {
1680
+ this.fabricObject.set({ fill: color });
1681
+ this.data.color = color;
1682
+ this.redraw();
1683
+ };
1684
+ /**
1685
+ * @override
1686
+ * @inheritDoc
1687
+ */
1688
+ Rectangle.prototype.getStrokeColor = function () {
1689
+ return this.fabricObject.stroke;
1690
+ };
1691
+ /**
1692
+ * @override
1693
+ * @inheritDoc
1694
+ */
1695
+ Rectangle.prototype.setStrokeColor = function (color) {
1696
+ this.fabricObject.set({ stroke: color });
1697
+ this.data.color = color;
1698
+ this.redraw();
1699
+ };
1700
+ /**
1701
+ * @override
1702
+ * @inheritDoc
1703
+ */
1704
+ Rectangle.prototype.getStrokeWidth = function () {
1705
+ return this.fabricObject.strokeWidth;
1706
+ };
1707
+ /**
1708
+ * @override
1709
+ * @inheritDoc
1710
+ */
1711
+ Rectangle.prototype.setStrokeWidth = function (width) {
1712
+ this.fabricObject.set({ strokeWidth: width });
1713
+ this.data.strokeWidth = width;
1714
+ this.redraw();
1715
+ };
1716
+ /**
1717
+ * @override
1718
+ * @inheritDoc
1719
+ */
1720
+ Rectangle.prototype.centerHorizontally = function () {
1721
+ _super.prototype.centerHorizontallyInternal.call(this);
1722
+ };
1723
+ /**
1724
+ * @override
1725
+ * @inheritDoc
1726
+ */
1727
+ Rectangle.prototype.centerVertically = function () {
1728
+ _super.prototype.centerVerticallyInternal.call(this);
1729
+ };
1730
+ /**
1731
+ * @override
1732
+ * @inheritDoc
1733
+ */
1734
+ Rectangle.prototype.nudgeUp = function () {
1735
+ _super.prototype.nudgeInternal.call(this, 0, -1);
1736
+ };
1737
+ /**
1738
+ * @override
1739
+ * @inheritDoc
1740
+ */
1741
+ Rectangle.prototype.nudgeDown = function () {
1742
+ _super.prototype.nudgeInternal.call(this, 0, +1);
1743
+ };
1744
+ /**
1745
+ * @override
1746
+ * @inheritDoc
1747
+ */
1748
+ Rectangle.prototype.nudgeLeft = function () {
1749
+ _super.prototype.nudgeInternal.call(this, -1, 0);
1750
+ };
1751
+ /**
1752
+ * @override
1753
+ * @inheritDoc
1754
+ */
1755
+ Rectangle.prototype.nudgeRight = function () {
1756
+ _super.prototype.nudgeInternal.call(this, +1, 0);
1757
+ };
1758
+ /**
1759
+ * @override
1760
+ * @inheritDoc
1761
+ */
1762
+ Rectangle.prototype.afterScale = function (event) {
1763
+ this.updateDimensions();
1764
+ var _a = this.getDimensions(), width = _a.width, height = _a.height;
1765
+ this.fabricObject.set({ scaleX: 1, scaleY: 1, width: width.px, height: height.px });
1766
+ this.updateDimensions();
1767
+ };
1768
+ return Rectangle;
1769
+ }(AbstractCanvasObject));
1770
+
1771
+ var RichText = /** @class */ (function (_super) {
1772
+ __extends(RichText, _super);
1773
+ function RichText(canvas, fabricObject, persistedField) {
1774
+ var _this = _super.call(this, canvas, fabricObject, persistedField) || this;
1775
+ _this.data.type = exports.ObjectType.RICH_TEXT;
1776
+ return _this;
1777
+ }
1778
+ Object.defineProperty(RichText.prototype, "htmlContent", {
1779
+ /**
1780
+ * @override
1781
+ * @inheritDoc
1782
+ */
1783
+ get: function () {
1784
+ return this.data.userText;
1785
+ },
1786
+ /**
1787
+ * @override
1788
+ * @inheritDoc
1789
+ */
1790
+ set: function (text) {
1791
+ this.data.userText = text;
1792
+ },
1793
+ enumerable: false,
1794
+ configurable: true
1795
+ });
1796
+ /**
1797
+ * @override
1798
+ * @inheritDoc
1799
+ */
1800
+ RichText.prototype.setRichTextContent = function (renderedContentUrl, htmlContent) {
1801
+ return __awaiter(this, void 0, void 0, function () {
1802
+ var canvasWidthPx;
1803
+ return __generator(this, function (_a) {
1804
+ switch (_a.label) {
1805
+ case 0:
1806
+ canvasWidthPx = this.canvas.getDimensions().widthPx;
1807
+ if (!renderedContentUrl)
1808
+ return [2 /*return*/];
1809
+ this.htmlContent = htmlContent;
1810
+ return [4 /*yield*/, this.setImageUrl(renderedContentUrl)];
1811
+ case 1:
1812
+ _a.sent();
1813
+ this.setImageWidth(canvasWidthPx);
1814
+ return [2 /*return*/];
1815
+ }
1816
+ });
1817
+ });
1818
+ };
1819
+ return RichText;
1820
+ }(Image));
1821
+
1822
+ var Text = /** @class */ (function (_super) {
1823
+ __extends(Text, _super);
1824
+ function Text(canvas, fabricObject, persistedField) {
1825
+ var _this_1 = _super.call(this, exports.ObjectType.TEXT, canvas, fabricObject, persistedField) || this;
1826
+ _this_1.canvas = canvas;
1827
+ _this_1.fontLibrary = canvas.getFontLibrary();
1828
+ _this_1.baseComponentHeight = _this_1.fabricObject.height;
1829
+ _this_1.text$ = new rxjs.BehaviorSubject(_this_1.fabricObject.text);
1830
+ _this_1.data.userText = _this_1.fabricObject.text;
1831
+ _this_1.textSelection$ = new rxjs.BehaviorSubject(new TextSelection(_this_1.fabricObject, _this_1.fontLibrary));
1832
+ _this_1.fabricObject.set({ strokeWidth: 0 });
1833
+ _this_1.fabricObject.on("changed", function () { return _this_1.onTextChange(); });
1834
+ _this_1.fabricObject.on("selection:changed", function () { return _this_1.onSelectionChange(); });
1835
+ _this_1.applyBulletListMonkeyPatches();
1836
+ return _this_1;
1837
+ }
1838
+ /**
1839
+ * @override
1840
+ * @inheritDoc
1841
+ */
1842
+ Text.prototype.getText = function () {
1843
+ return this.text$.value;
1844
+ };
1845
+ /**
1846
+ * @override
1847
+ * @inheritDoc
1848
+ */
1849
+ Text.prototype.getText$ = function () {
1850
+ return this.text$;
1851
+ };
1852
+ /**
1853
+ * @override
1854
+ * @inheritDoc
1855
+ */
1856
+ Text.prototype.setText = function (text) {
1857
+ var style = this.fabricObject.getStyleAtPosition(0, true);
1858
+ this.fabricObject.set({ text: text });
1859
+ this.data.userText = this.fabricObject.text;
1860
+ this.text$.next(text);
1861
+ this.fabricObject.setSelectionStyles(style, 0, text.length);
1862
+ this.redraw();
1863
+ };
1864
+ /**
1865
+ * @override
1866
+ * @inheritDoc
1867
+ */
1868
+ Text.prototype.replaceText = function (target, replacement) {
1869
+ var start = this.getText().indexOf(target);
1870
+ this.fabricObject.insertChars(replacement, null, start, start + target.length);
1871
+ this.redraw();
1872
+ this.data.userText = this.fabricObject.text;
1873
+ this.text$.next(this.fabricObject.text);
1874
+ };
1875
+ /**
1876
+ * @override
1877
+ * @inheritDoc
1878
+ */
1879
+ Text.prototype.insertText = function (text, style, start, end) {
1880
+ this.fabricObject.insertChars(text, style, start, end);
1881
+ var newCursorLocation = start + text.length;
1882
+ this.fabricObject.selectionStart = newCursorLocation;
1883
+ this.fabricObject.selectionEnd = newCursorLocation;
1884
+ this.redraw();
1885
+ this.data.userText = this.fabricObject.text;
1886
+ this.text$.next(this.fabricObject.text);
1887
+ };
1888
+ /**
1889
+ * @override
1890
+ * @inheritDoc
1891
+ */
1892
+ Text.prototype.insertTextAtSelection = function (text, style) {
1893
+ var selection = this.getTextSelection();
1894
+ this.insertText(text, style, selection.start, selection.end);
1895
+ };
1896
+ /**
1897
+ * @override
1898
+ * @inheritDoc
1899
+ */
1900
+ Text.prototype.getColor = function () {
1901
+ return this.textSelection$.value.fill;
1902
+ };
1903
+ /**
1904
+ * @override
1905
+ * @inheritDoc
1906
+ */
1907
+ Text.prototype.setColor = function (color) {
1908
+ if (this.hasTextSelection()) {
1909
+ this.fabricObject.setSelectionStyles({ fill: color });
1910
+ }
1911
+ else {
1912
+ this.fabricObject.set({ fill: color });
1913
+ }
1914
+ this.data.color = color;
1915
+ this.updateTextSelection();
1916
+ this.redraw();
1917
+ };
1918
+ /**
1919
+ * @override
1920
+ * @inheritDoc
1921
+ */
1922
+ Text.prototype.getTextSelection = function () {
1923
+ return this.textSelection$.value;
1924
+ };
1925
+ /**
1926
+ * @override
1927
+ * @inheritDoc
1928
+ */
1929
+ Text.prototype.getTextSelection$ = function () {
1930
+ return this.textSelection$;
1931
+ };
1932
+ /**
1933
+ * @override
1934
+ * @inheritDoc
1935
+ */
1936
+ Text.prototype.setTextAlign = function (alignment) {
1937
+ this.fabricObject.set({ textAlign: alignment });
1938
+ this.redraw();
1939
+ this.updateTextSelection();
1940
+ };
1941
+ /**
1942
+ * @override
1943
+ * @inheritDoc
1944
+ */
1945
+ Text.prototype.setCharSpacing = function (spacing) {
1946
+ this.fabricObject.set({ charSpacing: spacing });
1947
+ this.redraw();
1948
+ this.updateTextSelection();
1949
+ };
1950
+ /**
1951
+ * @override
1952
+ * @inheritDoc
1953
+ */
1954
+ Text.prototype.setLineHeight = function (height) {
1955
+ this.fabricObject.set({ lineHeight: height });
1956
+ this.redraw();
1957
+ this.updateTextSelection();
1958
+ };
1959
+ /**
1960
+ * @override
1961
+ * @inheritDoc
1962
+ */
1963
+ Text.prototype.setBold = function (bold) {
1964
+ if (bold === void 0) { bold = true; }
1965
+ if (this.hasTextSelection()) {
1966
+ var start = this.textSelection$.value.start;
1967
+ for (var i = 0; i < this.textSelection$.value.length; i++) {
1968
+ var style = this.fabricObject.getStyleAtPosition(start + i, true);
1969
+ var font = this.fontLibrary.getFont(style.fontFamily);
1970
+ var fontWeight = bold ? font.boldWeight : font.normalWeight;
1971
+ this.fabricObject.setSelectionStyles({ fontWeight: fontWeight }, start + i, start + i + 1);
1972
+ }
1973
+ }
1974
+ else {
1975
+ var font = this.fontLibrary.getFont(this.fabricObject.fontFamily);
1976
+ var fontWeight = bold ? font.boldWeight : font.normalWeight;
1977
+ this.fabricObject.set({ fontWeight: fontWeight });
1978
+ }
1979
+ this.redraw();
1980
+ this.updateTextSelection();
1981
+ };
1982
+ /**
1983
+ * @override
1984
+ * @inheritDoc
1985
+ */
1986
+ Text.prototype.setBoldRegion = function (start, end, bold) {
1987
+ if (bold === void 0) { bold = true; }
1988
+ if (start > end)
1989
+ throw Error("Bad region specified: [" + start + " - " + end + "]");
1990
+ for (var i = start; i < end; i++) {
1991
+ var style = this.fabricObject.getStyleAtPosition(i, true);
1992
+ var font = this.fontLibrary.getFont(style.fontFamily);
1993
+ style.fontWeight = bold ? font.boldWeight : font.normalWeight;
1994
+ this.fabricObject.setSelectionStyles(style, i, i + 1);
1995
+ }
1996
+ this.redraw();
1997
+ };
1998
+ /**
1999
+ * @override
2000
+ * @inheritDoc
2001
+ */
2002
+ Text.prototype.setItalic = function (italic) {
2003
+ if (italic === void 0) { italic = true; }
2004
+ if (this.hasTextSelection()) {
2005
+ this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" });
2006
+ }
2007
+ else {
2008
+ this.fabricObject.set({ fontStyle: italic ? "italic" : "" });
2009
+ }
2010
+ this.redraw();
2011
+ this.updateTextSelection();
2012
+ };
2013
+ /**
2014
+ * @override
2015
+ * @inheritDoc
2016
+ */
2017
+ Text.prototype.setItalicRegion = function (start, end, italic) {
2018
+ if (italic === void 0) { italic = true; }
2019
+ if (start > end)
2020
+ throw Error("Bad region specified: [" + start + " - " + end + "]");
2021
+ this.fabricObject.setSelectionStyles({ fontStyle: italic ? "italic" : "" }, start, end);
2022
+ this.redraw();
2023
+ };
2024
+ /**
2025
+ * @override
2026
+ * @inheritDoc
2027
+ */
2028
+ Text.prototype.setStrikethrough = function (strikethrough) {
2029
+ if (strikethrough === void 0) { strikethrough = true; }
2030
+ if (this.hasTextSelection()) {
2031
+ this.fabricObject.setSelectionStyles({ linethrough: strikethrough });
2032
+ }
2033
+ else {
2034
+ this.fabricObject.set({ linethrough: strikethrough });
2035
+ }
2036
+ this.redraw();
2037
+ this.updateTextSelection();
2038
+ };
2039
+ /**
2040
+ * @override
2041
+ * @inheritDoc
2042
+ */
2043
+ Text.prototype.setUnderline = function (underline) {
2044
+ if (underline === void 0) { underline = true; }
2045
+ this.fabricObject.setSelectionStyles({ underline: underline });
2046
+ this.redraw();
2047
+ this.updateTextSelection();
2048
+ };
2049
+ /**
2050
+ * @override
2051
+ * @inheritDoc
2052
+ */
2053
+ Text.prototype.setFont = function (font) {
2054
+ if (this.hasTextSelection()) {
2055
+ this.fabricObject.setSelectionStyles({ fontFamily: font.family, fontWeight: font.normalWeight });
2056
+ }
2057
+ else {
2058
+ this.fabricObject.set({ fontFamily: font.family, fontWeight: font.normalWeight });
2059
+ }
2060
+ this.redraw();
2061
+ this.updateTextSelection();
2062
+ };
2063
+ /**
2064
+ * @override
2065
+ * @inheritDoc
2066
+ */
2067
+ Text.prototype.setFontSize = function (fontSize) {
2068
+ if (this.hasTextSelection()) {
2069
+ this.fabricObject.setSelectionStyles({ fontSize: fontSize });
2070
+ }
2071
+ else {
2072
+ this.fabricObject.set({ fontSize: fontSize });
2073
+ }
2074
+ this.redraw();
2075
+ this.updateTextSelection();
2076
+ };
2077
+ /**
2078
+ * @override
2079
+ * @inheritDoc
2080
+ */
2081
+ Text.prototype.setTextBackgroundColor = function (color) {
2082
+ if (this.hasTextSelection()) {
2083
+ this.fabricObject.setSelectionStyles({ textBackgroundColor: color });
2084
+ }
2085
+ else {
2086
+ this.fabricObject.set({ textBackgroundColor: color });
2087
+ }
2088
+ this.redraw();
2089
+ this.updateTextSelection();
2090
+ };
2091
+ /**
2092
+ * @override
2093
+ * @inheritDoc
2094
+ */
2095
+ Text.prototype.centerHorizontally = function () {
2096
+ _super.prototype.centerHorizontallyInternal.call(this);
2097
+ };
2098
+ /**
2099
+ * @override
2100
+ * @inheritDoc
2101
+ */
2102
+ Text.prototype.centerVertically = function () {
2103
+ _super.prototype.centerVerticallyInternal.call(this);
2104
+ };
2105
+ /**
2106
+ * @override
2107
+ * @inheritDoc
2108
+ */
2109
+ Text.prototype.nudgeUp = function () {
2110
+ _super.prototype.nudgeInternal.call(this, 0, -1);
2111
+ };
2112
+ /**
2113
+ * @override
2114
+ * @inheritDoc
2115
+ */
2116
+ Text.prototype.nudgeDown = function () {
2117
+ _super.prototype.nudgeInternal.call(this, 0, +1);
2118
+ };
2119
+ /**
2120
+ * @override
2121
+ * @inheritDoc
2122
+ */
2123
+ Text.prototype.nudgeLeft = function () {
2124
+ _super.prototype.nudgeInternal.call(this, -1, 0);
2125
+ };
2126
+ /**
2127
+ * @override
2128
+ * @inheritDoc
2129
+ */
2130
+ Text.prototype.nudgeRight = function () {
2131
+ _super.prototype.nudgeInternal.call(this, +1, 0);
2132
+ };
2133
+ /**
2134
+ * @override
2135
+ * @inheritDoc
2136
+ */
2137
+ Text.prototype.getBackgroundColor = function () {
2138
+ return this.fabricObject.backgroundColor;
2139
+ };
2140
+ /**
2141
+ * @override
2142
+ * @inheritDoc
2143
+ */
2144
+ Text.prototype.setBackgroundColor = function (color) {
2145
+ this.fabricObject.set({ backgroundColor: color });
2146
+ this.redraw();
2147
+ };
2148
+ /**
2149
+ * @override
2150
+ * @inheritDoc
2151
+ */
2152
+ Text.prototype.setPrefillType = function (prefillType) {
2153
+ this.data.prefillType = prefillType;
2154
+ };
2155
+ /**
2156
+ * @override
2157
+ * @inheritDoc
2158
+ */
2159
+ Text.prototype.getPrefillType = function () {
2160
+ return this.data.prefillType;
2161
+ };
2162
+ /**
2163
+ * @override
2164
+ * @inheritDoc
2165
+ */
2166
+ Text.prototype.getBulletMargin = function () {
2167
+ var _this_1 = this;
2168
+ if (!this.isBulleted())
2169
+ return 0;
2170
+ var fontSize = 0;
2171
+ _.each(this.fabricObject._textLines, function (textLine, lineIndex) {
2172
+ fontSize = Math.max(fontSize, _this_1.fabricObject.getValueOfPropertyAt(lineIndex, 0, "fontSize"));
2173
+ });
2174
+ return fontSize * 0.6;
2175
+ };
2176
+ /**
2177
+ * @override
2178
+ * @inheritDoc
2179
+ */
2180
+ Text.prototype.getOrderedListMargin = function () {
2181
+ if (!this.isOrderedList())
2182
+ return 0;
2183
+ var orderedListMarkerEntities = this.fabricObject._orderedListMarkerEntities;
2184
+ var max = _(orderedListMarkerEntities)
2185
+ .filter(function (x) { return !!x; })
2186
+ .map(function (x) { return x.getBoundingRect(true, true).width; })
2187
+ .max();
2188
+ return (max * 1.2) || 0;
2189
+ };
2190
+ /**
2191
+ * @override
2192
+ * @inheritDoc
2193
+ */
2194
+ Text.prototype.isResizeCanvas = function () {
2195
+ return this.data.resizeCanvas;
2196
+ };
2197
+ /**
2198
+ * @override
2199
+ * @inheritDoc
2200
+ */
2201
+ Text.prototype.setResizeCanvas = function (value) {
2202
+ this.baseComponentHeight = this.fabricObject.height;
2203
+ this.data.resizeCanvas = value;
2204
+ };
2205
+ /**
2206
+ * @override
2207
+ * @inheritDoc
2208
+ */
2209
+ Text.prototype.focus = function () {
2210
+ this.fabricObject.hiddenTextarea.focus();
2211
+ };
2212
+ /**
2213
+ * @override
2214
+ * @inheritDoc
2215
+ */
2216
+ Text.prototype.isEditing = function () {
2217
+ return this.fabricObject.isEditing;
2218
+ };
2219
+ /**
2220
+ * @override
2221
+ * @inheritDoc
2222
+ */
2223
+ Text.prototype.enterEditing = function () {
2224
+ if (!this.isEditing()) {
2225
+ this.fabricObject.enterEditing();
2226
+ this.focus();
2227
+ this.selectAllText();
2228
+ this.redraw();
2229
+ }
2230
+ };
2231
+ /**
2232
+ * @override
2233
+ * @inheritDoc
2234
+ */
2235
+ Text.prototype.selectAllText = function () {
2236
+ this.fabricObject.selectAll();
2237
+ };
2238
+ /**
2239
+ * @override
2240
+ * @inheritDoc
2241
+ */
2242
+ Text.prototype.isBulleted = function () {
2243
+ return this.data.bulleted || false;
2244
+ };
2245
+ /**
2246
+ * @override
2247
+ * @inheritDoc
2248
+ */
2249
+ Text.prototype.enableBullets = function () {
2250
+ this.disableOrderedList();
2251
+ this.fabricObject["objectCaching"] = false;
2252
+ this.fabricObject["_bullets"] = this.fabricObject["_bullets"] || {};
2253
+ this.data.bulleted = true;
2254
+ this.notifyCanvasOfTextChanges();
2255
+ this.redraw();
2256
+ };
2257
+ /**
2258
+ * @override
2259
+ * @inheritDoc
2260
+ */
2261
+ Text.prototype.disableBullets = function () {
2262
+ this.removeBullets();
2263
+ this.data.bulleted = false;
2264
+ this.notifyCanvasOfTextChanges();
2265
+ this.redraw();
2266
+ };
2267
+ /**
2268
+ * @override
2269
+ * @inheritDoc
2270
+ */
2271
+ Text.prototype.isOrderedList = function () {
2272
+ return this.fabricObject._isOrderedList || false;
2273
+ };
2274
+ /**
2275
+ * @override
2276
+ * @inheritDoc
2277
+ */
2278
+ Text.prototype.enableOrderedList = function () {
2279
+ this.disableBullets();
2280
+ this.fabricObject.objectCaching = false;
2281
+ this.fabricObject._isOrderedList = true;
2282
+ this.notifyCanvasOfTextChanges();
2283
+ this.redraw();
2284
+ };
2285
+ /**
2286
+ * @override
2287
+ * @inheritDoc
2288
+ */
2289
+ Text.prototype.disableOrderedList = function () {
2290
+ this.removeOrderedListMarkers();
2291
+ delete this.fabricObject._isOrderedList;
2292
+ this.notifyCanvasOfTextChanges();
2293
+ this.redraw();
2294
+ };
2295
+ /**
2296
+ * @override
2297
+ * @inheritDoc
2298
+ */
2299
+ Text.prototype.setOrderedListStart = function (start) {
2300
+ this.fabricObject._orderedListStart = start;
2301
+ this.notifyCanvasOfTextChanges();
2302
+ this.redraw();
2303
+ };
2304
+ /**
2305
+ * @override
2306
+ * @inheritDoc
2307
+ */
2308
+ Text.prototype.getOrderedListStart = function () {
2309
+ return this.fabricObject._orderedListStart || 1;
2310
+ };
2311
+ Text.prototype.getSizeIncreaseSinceCreation = function () {
2312
+ return Math.max(0, this.fabricObject.height - this.baseComponentHeight);
2313
+ };
2314
+ Text.prototype.removeBullets = function () {
2315
+ var _this_1 = this;
2316
+ if (this.data.bulleted) {
2317
+ var bullets = this.fabricObject["_bullets"];
2318
+ delete this.fabricObject["_bullets"];
2319
+ _.each(bullets, function (bullet) { return _this_1.canvas.removeFabricObject(bullet); });
2320
+ this.fabricObject["objectCaching"] = true;
2321
+ }
2322
+ };
2323
+ Text.prototype.removeOrderedListMarkers = function () {
2324
+ var _this_1 = this;
2325
+ if (this.fabricObject._isOrderedList) {
2326
+ var markerEntities = this.fabricObject._orderedListMarkerEntities;
2327
+ delete this.fabricObject._orderedListMarkerEntities;
2328
+ _.each(markerEntities, function (marker) { return _this_1.canvas.removeFabricObject(marker); });
2329
+ this.fabricObject["objectCaching"] = true;
2330
+ }
2331
+ };
2332
+ Text.prototype.applyBulletListMonkeyPatches = function () {
2333
+ var _this = this;
2334
+ if (this.data.bulleted)
2335
+ this.enableBullets();
2336
+ if (this.fabricObject._isOrderedList)
2337
+ this.enableOrderedList();
2338
+ var originalRender = this.fabricObject["_render"];
2339
+ var fabric = this.canvas.fabric;
2340
+ this.fabricObject["_render"] = function (ctx) {
2341
+ var fabricText = this;
2342
+ if (fabricText["_bullets"]) {
2343
+ // Determine list of active bullets
2344
+ var currentBullets_1 = fabricText["_bullets"];
2345
+ var activeBullets_1 = {};
2346
+ _.each(fabricText._textLines, function (textLine, lineIndex) {
2347
+ if (textLine.length) {
2348
+ // Start of real lines will have offset 0 in styleMap
2349
+ var styleMap = fabricText._styleMap[lineIndex];
2350
+ if (styleMap.offset === 0) {
2351
+ if (currentBullets_1[lineIndex]) {
2352
+ // Reuse existing bullet for this line
2353
+ activeBullets_1[lineIndex] = currentBullets_1[lineIndex];
2354
+ }
2355
+ else {
2356
+ // Create new bullet for this line
2357
+ var options = {
2358
+ left: 0,
2359
+ top: 0,
2360
+ radius: 2,
2361
+ fill: fabricText.fill,
2362
+ scaleX: fabricText.scaleX,
2363
+ scaleY: fabricText.scaleY,
2364
+ strokeWidth: 0,
2365
+ lockMovementX: true,
2366
+ lockMovementY: true,
2367
+ hasControls: false,
2368
+ selectable: false,
2369
+ excludeFromJson: true
2370
+ };
2371
+ activeBullets_1[lineIndex] = new fabric.Circle(options);
2372
+ }
2373
+ }
2374
+ }
2375
+ });
2376
+ // Add/Remove bullets from canvas
2377
+ var canvas_1 = fabricText.canvas;
2378
+ var canvasDirty_1 = false;
2379
+ canvas_1.renderOnAddRemove = false;
2380
+ _.each(activeBullets_1, function (bullet) {
2381
+ if (!canvas_1.contains(bullet)) {
2382
+ canvas_1.add(bullet);
2383
+ canvasDirty_1 = true;
2384
+ }
2385
+ });
2386
+ _.each(currentBullets_1, function (bullet, key) {
2387
+ if (!activeBullets_1[key]) {
2388
+ canvas_1.remove(bullet);
2389
+ canvasDirty_1 = true;
2390
+ }
2391
+ });
2392
+ canvas_1.renderOnAddRemove = true;
2393
+ fabricText["_bullets"] = activeBullets_1;
2394
+ if (canvasDirty_1) {
2395
+ // Fabric doesn't like it when you add new things within render so use a sneaky timeout to delay render
2396
+ setTimeout(canvas_1.renderAll.bind(canvas_1));
2397
+ }
2398
+ }
2399
+ if (fabricText._isOrderedList) {
2400
+ var existingMarkers_1 = fabricText._orderedListMarkerEntities || [];
2401
+ var activeMarkers_1 = [];
2402
+ _.each(fabricText._textLines, function (textLine, lineIndex) {
2403
+ if (textLine.length) {
2404
+ // Start of real lines will have offset 0 in styleMap
2405
+ var styleMap = fabricText._styleMap[lineIndex];
2406
+ if (styleMap.offset === 0) {
2407
+ if (existingMarkers_1[lineIndex]) {
2408
+ // Reuse existing marker for this line
2409
+ activeMarkers_1[lineIndex] = existingMarkers_1[lineIndex];
2410
+ }
2411
+ else {
2412
+ // Create new marker for this line
2413
+ var textbox = new fabric.Textbox(lineIndex + ".", {
2414
+ left: 0,
2415
+ top: 0,
2416
+ fill: fabricText.fill,
2417
+ scaleX: fabricText.scaleX,
2418
+ scaleY: fabricText.scaleY,
2419
+ strokeWidth: 0,
2420
+ lockMovementX: true,
2421
+ lockMovementY: true,
2422
+ hasControls: false,
2423
+ selectable: false
2424
+ });
2425
+ textbox._isSlaveObject = true;
2426
+ activeMarkers_1[lineIndex] = textbox;
2427
+ }
2428
+ }
2429
+ }
2430
+ });
2431
+ // Add/Remove markers from canvas
2432
+ var canvas_2 = fabricText.canvas;
2433
+ var canvasDirty_2 = false;
2434
+ canvas_2.renderOnAddRemove = false;
2435
+ _.each(activeMarkers_1, function (marker) {
2436
+ if (!marker)
2437
+ return;
2438
+ if (!canvas_2.contains(marker)) {
2439
+ canvas_2.add(marker);
2440
+ canvasDirty_2 = true;
2441
+ }
2442
+ });
2443
+ _.each(existingMarkers_1, function (marker, key) {
2444
+ if (!marker)
2445
+ return;
2446
+ if (!activeMarkers_1[key]) {
2447
+ canvas_2.remove(marker);
2448
+ canvasDirty_2 = true;
2449
+ }
2450
+ });
2451
+ canvas_2.renderOnAddRemove = true;
2452
+ fabricText._orderedListMarkerEntities = activeMarkers_1;
2453
+ if (canvasDirty_2) {
2454
+ // Fabric doesn't like it when you add new things within render so use a sneaky timeout to delay render
2455
+ setTimeout(canvas_2.renderAll.bind(canvas_2));
2456
+ }
2457
+ }
2458
+ originalRender.apply(fabricText, [ctx]);
2459
+ };
2460
+ var originalRenderTextLine = this.fabricObject["_renderTextLine"];
2461
+ this.fabricObject["_renderTextLine"] = function (method, ctx, line, left, top, lineIndex) {
2462
+ var fabricText = this;
2463
+ var bullets = fabricText._bullets;
2464
+ if (bullets && bullets[lineIndex]) {
2465
+ var bullet = bullets[lineIndex];
2466
+ var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
2467
+ var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
2468
+ var radius = fontSize / 5;
2469
+ var angle = fabricText.angle;
2470
+ var theta = angle * Math.PI / 180;
2471
+ var x = -radius * 2;
2472
+ var y = (fabricText.height / 2) + top - (fontSize / 1.5);
2473
+ var xOffset = (x * Math.cos(theta)) - (y * Math.sin(theta));
2474
+ var yOffset = (x * Math.sin(theta)) + (y * Math.cos(theta));
2475
+ var bulletCenterOffset = [-radius * Math.sqrt(2) / 2, -radius * Math.sqrt(2) / 2];
2476
+ bullet.set({
2477
+ radius: radius,
2478
+ fill: color,
2479
+ left: fabricText.left + xOffset + bulletCenterOffset[0],
2480
+ top: fabricText.top + yOffset + bulletCenterOffset[1]
2481
+ });
2482
+ }
2483
+ var orderedListMarkerEntities = fabricText._orderedListMarkerEntities;
2484
+ var xShift = -_this.getOrderedListMargin() + 1;
2485
+ if (orderedListMarkerEntities && orderedListMarkerEntities[lineIndex]) {
2486
+ var entry = orderedListMarkerEntities[lineIndex];
2487
+ var fontSize = this.getValueOfPropertyAt(lineIndex, 0, "fontSize");
2488
+ var fontFamily = this.getValueOfPropertyAt(lineIndex, 0, "fontFamily");
2489
+ var fontWeight = this.getValueOfPropertyAt(lineIndex, 0, "fontWeight");
2490
+ var fontStyle = this.getValueOfPropertyAt(lineIndex, 0, "fontStyle");
2491
+ var color = this.getValueOfPropertyAt(lineIndex, 0, "fill");
2492
+ var angle = fabricText.angle;
2493
+ var theta = angle * Math.PI / 180;
2494
+ var yShift = (fabricText.height / 2) + top - fontSize - 1;
2495
+ var xOffset = (xShift * Math.cos(theta)) - (yShift * Math.sin(theta));
2496
+ var yOffset = (xShift * Math.sin(theta)) + (yShift * Math.cos(theta));
2497
+ var lineNumber = _this.getOrderedListStart();
2498
+ for (var i = 0; i < lineIndex; i++) {
2499
+ if (orderedListMarkerEntities[i])
2500
+ lineNumber++;
2501
+ }
2502
+ entry.set({
2503
+ width: 1,
2504
+ fontSize: fontSize,
2505
+ fontFamily: fontFamily,
2506
+ fontWeight: fontWeight,
2507
+ fontStyle: fontStyle,
2508
+ fill: color,
2509
+ left: fabricText.left + xOffset,
2510
+ top: fabricText.top + yOffset,
2511
+ angle: fabricText.angle,
2512
+ text: lineNumber + "."
2513
+ });
2514
+ }
2515
+ originalRenderTextLine.apply(fabricText, [method, ctx, line, left, top, lineIndex]);
2516
+ };
2517
+ };
2518
+ /**
2519
+ * @override
2520
+ * @inheritDoc
2521
+ */
2522
+ Text.prototype.updateFabricObjectBehavior = function () {
2523
+ _super.prototype.updateFabricObjectBehavior.call(this);
2524
+ var profile = this.canvas.getProfile();
2525
+ var allowManualPositioning = !this.canvas.getLayoutManager().isEnforcedPositioning;
2526
+ this.fabricObject.set({
2527
+ lockScalingY: true,
2528
+ lockScalingX: this.isPinToBottom(),
2529
+ lockScalingFlip: true
2530
+ });
2531
+ this.fabricObject.setControlsVisibility({
2532
+ tl: false,
2533
+ tr: false,
2534
+ br: false,
2535
+ bl: false,
2536
+ ml: allowManualPositioning && profile.allowScale && !this.isPinToBottom(),
2537
+ mt: false,
2538
+ mr: allowManualPositioning && profile.allowScale && !this.isPinToBottom(),
2539
+ mb: false
2540
+ });
2541
+ this.redraw();
2542
+ };
2543
+ Text.prototype.onTextChange = function () {
2544
+ this.data.userText = this.fabricObject.text;
2545
+ this.text$.next(this.fabricObject.text);
2546
+ if (this.getBoundingBox().width > this.canvas.getDimensions().widthPx) {
2547
+ this.fabricObject.set({ left: 0, width: this.canvas.getDimensions().widthPx });
2548
+ this.redraw();
2549
+ }
2550
+ };
2551
+ Text.prototype.onDelete = function () {
2552
+ this.removeBullets();
2553
+ };
2554
+ Text.prototype.onSelectionChange = function () {
2555
+ this.updateTextSelection();
2556
+ };
2557
+ Text.prototype.hasTextSelection = function () {
2558
+ return this.canvas.getSelection().isText && this.textSelection$.value.length > 0;
2559
+ };
2560
+ Text.prototype.updateTextSelection = function () {
2561
+ if (this.canvas.headless)
2562
+ return;
2563
+ this.textSelection$.next(new TextSelection(this.fabricObject, this.fontLibrary));
2564
+ this.notifyCanvasOfTextChanges();
2565
+ };
2566
+ Text.prototype.notifyCanvasOfTextChanges = function () {
2567
+ this.canvas.notifyTextChanged();
2568
+ };
2569
+ return Text;
2570
+ }(AbstractCanvasObject));
2571
+ var TextSelection = /** @class */ (function () {
2572
+ function TextSelection(fabricObject, fontLibrary) {
2573
+ this.fabricObject = fabricObject;
2574
+ this.fontLibrary = fontLibrary;
2575
+ this.start = this.fabricObject.selectionStart;
2576
+ this.end = this.fabricObject.selectionEnd;
2577
+ this.length = this.end - this.start;
2578
+ var cursorLoc = this.fabricObject.get2DCursorLocation();
2579
+ this.lineIndex = cursorLoc.lineIndex;
2580
+ this.charIndex = cursorLoc.charIndex;
2581
+ var style = this.fabricObject.getCompleteStyleDeclaration(this.lineIndex, this.charIndex);
2582
+ var hasSelection = this.length > 0;
2583
+ this.font = hasSelection ? this.fontLibrary.getFont(style.fontFamily) : this.fontLibrary.getFont(this.fabricObject.fontFamily);
2584
+ this.fontSize = hasSelection ? style.fontSize : this.fabricObject.fontSize;
2585
+ this.fontWeight = hasSelection ? style.fontWeight : this.fabricObject.fontWeight;
2586
+ this.bold = this.font.isBold(this.fontWeight);
2587
+ this.italic = hasSelection ? style.fontStyle === "italic" : this.fabricObject.fontStyle === "italic";
2588
+ this.underline = hasSelection ? style.underline : this.fabricObject.underline;
2589
+ this.strikethrough = hasSelection ? style.linethrough : this.fabricObject.linethrough;
2590
+ this.overline = hasSelection ? style.overline : this.fabricObject.overline;
2591
+ this.textBackgroundColor = hasSelection ? style.textBackgroundColor : this.fabricObject.textBackgroundColor;
2592
+ this.textAlign = this.fabricObject.textAlign;
2593
+ this.charSpacing = this.fabricObject.charSpacing;
2594
+ this.lineHeight = this.fabricObject.lineHeight;
2595
+ this.fill = style.fill;
2596
+ this.stroke = style.stroke;
2597
+ this.strokeWidth = style.strokeWidth;
2598
+ }
2599
+ return TextSelection;
2600
+ }());
2601
+
2602
+ var VerticalRule = /** @class */ (function (_super) {
2603
+ __extends(VerticalRule, _super);
2604
+ function VerticalRule(canvas, fabricObject, persistedField) {
2605
+ var _this = _super.call(this, exports.ObjectType.VERTICAL_RULE, canvas, fabricObject, persistedField) || this;
2606
+ _this.strokeWidth$ = new rxjs.BehaviorSubject(2);
2607
+ _this.canvas = canvas;
2608
+ _this.strokeWidth$.next(_this.getDimensions().width.px);
2609
+ _this.fabricObject.set({ strokeWidth: 0 });
2610
+ return _this;
2611
+ }
2612
+ /**
2613
+ * @override
2614
+ * @inheritDoc
2615
+ */
2616
+ VerticalRule.prototype.getStrokeWidth = function () {
2617
+ return this.fabricObject.width;
2618
+ };
2619
+ /**
2620
+ * @override
2621
+ * @inheritDoc
2622
+ */
2623
+ VerticalRule.prototype.getStrokeWidth$ = function () {
2624
+ return this.strokeWidth$;
2625
+ };
2626
+ /**
2627
+ * @override
2628
+ * @inheritDoc
2629
+ */
2630
+ VerticalRule.prototype.setStrokeWidth = function (width) {
2631
+ this.strokeWidth$.next(width);
2632
+ this.data.strokeWidth = width;
2633
+ this.setPosition({ width: width });
2634
+ this.canvas.notifyObjectListChanged();
2635
+ this.redraw();
2636
+ };
2637
+ /**
2638
+ * @override
2639
+ * @inheritDoc
2640
+ */
2641
+ VerticalRule.prototype.getColor = function () {
2642
+ return this.fabricObject.fill;
2643
+ };
2644
+ /**
2645
+ * @override
2646
+ * @inheritDoc
2647
+ */
2648
+ VerticalRule.prototype.setColor = function (color) {
2649
+ this.fabricObject.set({ fill: color, stroke: color });
2650
+ this.data.color = color;
2651
+ this.redraw();
2652
+ };
2653
+ /**
2654
+ * @override
2655
+ * @inheritDoc
2656
+ */
2657
+ VerticalRule.prototype.centerHorizontally = function () {
2658
+ _super.prototype.centerHorizontallyInternal.call(this);
2659
+ };
2660
+ /**
2661
+ * @override
2662
+ * @inheritDoc
2663
+ */
2664
+ VerticalRule.prototype.centerVertically = function () {
2665
+ _super.prototype.centerVerticallyInternal.call(this);
2666
+ };
2667
+ /**
2668
+ * @override
2669
+ * @inheritDoc
2670
+ */
2671
+ VerticalRule.prototype.nudgeUp = function () {
2672
+ _super.prototype.nudgeInternal.call(this, 0, -1);
2673
+ };
2674
+ /**
2675
+ * @override
2676
+ * @inheritDoc
2677
+ */
2678
+ VerticalRule.prototype.nudgeDown = function () {
2679
+ _super.prototype.nudgeInternal.call(this, 0, +1);
2680
+ };
2681
+ /**
2682
+ * @override
2683
+ * @inheritDoc
2684
+ */
2685
+ VerticalRule.prototype.nudgeLeft = function () {
2686
+ _super.prototype.nudgeInternal.call(this, -1, 0);
2687
+ };
2688
+ /**
2689
+ * @override
2690
+ * @inheritDoc
2691
+ */
2692
+ VerticalRule.prototype.nudgeRight = function () {
2693
+ _super.prototype.nudgeInternal.call(this, +1, 0);
2694
+ };
2695
+ return VerticalRule;
2696
+ }(AbstractCanvasObject));
2697
+
2698
+ /**
2699
+ * Profile with as many features disabled as possible.
2700
+ */
2701
+ var DefaultCanvasProfile = /** @class */ (function () {
2702
+ function DefaultCanvasProfile() {
2703
+ this.allowMultiSelect = false;
2704
+ this.enterTextEditImmediatelyOnSelect = true;
2705
+ this.allowObjectsToLeaveCanvas = false;
2706
+ this.allowMove = false;
2707
+ this.allowRotate = false;
2708
+ this.allowScale = false;
2709
+ this.defaultFont = "Lato";
2710
+ this.defaultFontSize = 9;
2711
+ this.defaultFontColor = "#000000";
2712
+ this.defaultLineHeight = 1.8;
2713
+ this.defaultCharacterSpacing = 0;
2714
+ this.defaultTextAlignment = "left";
2715
+ this.defaultBorderColor = "#000000";
2716
+ this.defaultBorderWidth = 1;
2717
+ this.defaultCutoffColor = "#000000";
2718
+ this.defaultCutoffWidth = 1;
2719
+ }
2720
+ return DefaultCanvasProfile;
2721
+ }());
2722
+
2723
+ (function (ImageType) {
2724
+ ImageType["DEFAULT"] = "DEFAULT";
2725
+ ImageType["BACKGROUND"] = "BACKGROUND";
2726
+ ImageType["LOGO"] = "LOGO";
2727
+ ImageType["PHOTO"] = "PHOTO";
2728
+ })(exports.ImageType || (exports.ImageType = {}));
2729
+
2730
+ (function (ObjectType) {
2731
+ ObjectType["TEXT"] = "TEXT";
2732
+ ObjectType["BORDER"] = "BORDER";
2733
+ ObjectType["IMAGE"] = "IMAGE";
2734
+ ObjectType["RECTANGLE"] = "RECTANGLE";
2735
+ ObjectType["LIBRARY_IMAGE"] = "LIBRARY_IMAGE";
2736
+ ObjectType["CUTOFF"] = "CUTOFF";
2737
+ ObjectType["VERTICAL_RULE"] = "VERTICAL_RULE";
2738
+ ObjectType["HORIZONTAL_RULE"] = "HORIZONTAL_RULE";
2739
+ ObjectType["RICH_TEXT"] = "RICH_TEXT";
2740
+ ObjectType["BACKGROUND_IMAGE"] = "BACKGROUND_IMAGE";
2741
+ })(exports.ObjectType || (exports.ObjectType = {}));
2742
+
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 rxjs.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 rxjs.BehaviorSubject(this.baseDimensions);
2759
+ this.dimensionRestrictions$ = new rxjs.BehaviorSubject(baseRestrictions);
2760
+ this.zoom$ = new rxjs.BehaviorSubject(1);
2761
+ this.profile$ = new rxjs.BehaviorSubject(new DefaultCanvasProfile());
2762
+ this.layoutManager$ = new rxjs.BehaviorSubject(new AdvancedLayoutManager(this));
2763
+ this.backgroundColor$ = new rxjs.BehaviorSubject(this.fabricCanvas.backgroundColor);
2764
+ this.objects$ = new rxjs.BehaviorSubject([]);
2765
+ this.selection$ = new rxjs.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 === exports.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(tsOptchain.oc(restrictions).width.min(dimensions.width), dimensions.width), Math.max(tsOptchain.oc(restrictions).width.max(dimensions.width))), Math.min(Math.max(tsOptchain.oc(restrictions).height.min(dimensions.height), dimensions.height), Math.max(tsOptchain.oc(restrictions).height.max(dimensions.height))));
2929
+ this.setBaseDimensions(newDimensions);
2930
+ }
2931
+ };
2932
+ AbstractInteractiveCanvas.prototype.getMargin = function () {
2933
+ var borderWidth = this.getObjectsByTypeInternal(exports.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(exports.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(exports.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(exports.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(exports.ObjectType.TEXT, exports.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 exports.ObjectType.TEXT:
3622
+ return new Text(this, fabricObject, persistedField);
3623
+ case exports.ObjectType.RECTANGLE:
3624
+ return new Rectangle(this, fabricObject, persistedField);
3625
+ case exports.ObjectType.BORDER:
3626
+ return new Border(this, fabricObject, persistedField);
3627
+ case exports.ObjectType.CUTOFF:
3628
+ return new Cutoff(this, fabricObject, persistedField);
3629
+ case exports.ObjectType.IMAGE:
3630
+ case exports.ObjectType.LIBRARY_IMAGE:
3631
+ return new Image(this, fabricObject, persistedField);
3632
+ case exports.ObjectType.HORIZONTAL_RULE:
3633
+ return new HorizontalRule(this, fabricObject, persistedField);
3634
+ case exports.ObjectType.VERTICAL_RULE:
3635
+ return new VerticalRule(this, fabricObject, persistedField);
3636
+ case exports.ObjectType.RICH_TEXT:
3637
+ return new RichText(this, fabricObject, persistedField);
3638
+ case exports.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() === exports.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 tsOptchain.oc(restrictions).height.min() != undefined && dimensions.height < tsOptchain.oc(restrictions).height.min()
3724
+ || tsOptchain.oc(restrictions).height.max() != undefined && dimensions.height > tsOptchain.oc(restrictions).height.max()
3725
+ || tsOptchain.oc(restrictions).width.min() != undefined && dimensions.width < tsOptchain.oc(restrictions).width.min()
3726
+ || tsOptchain.oc(restrictions).width.max() != undefined && dimensions.width > tsOptchain.oc(restrictions).width.max()
3727
+ || tsOptchain.oc(restrictions).volume.min() != undefined && dimensions.height * dimensions.width < tsOptchain.oc(restrictions).volume.min()
3728
+ || tsOptchain.oc(restrictions).volume.max() != undefined && dimensions.height * dimensions.width > tsOptchain.oc(restrictions).volume.max();
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() === exports.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.fabric, new fabric.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() !== exports.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(exports.ObjectType.CUTOFF)
3924
+ .forEach(function (cutoff) { return cutoff.updatePosition(); });
3925
+ };
3926
+ return RepositionCutoffsLayoutFunction;
3927
+ }());
3928
+
3929
+ var PinToBottomLayoutFunction = /** @class */ (function () {
3930
+ function PinToBottomLayoutFunction() {
3931
+ }
3932
+ PinToBottomLayoutFunction.prototype.execute = function (canvas) {
3933
+ canvas.getObjectsInternal()
3934
+ .forEach(function (object) { return object.moveToPinnedPosition(); });
3935
+ };
3936
+ return PinToBottomLayoutFunction;
3937
+ }());
3938
+
3939
+ var ResizeCanvasLayoutFunction = /** @class */ (function () {
3940
+ function ResizeCanvasLayoutFunction() {
3941
+ }
3942
+ ResizeCanvasLayoutFunction.prototype.execute = function (canvas) {
3943
+ if (canvas.getLayoutManager().isEnforcedPositioning)
3944
+ return;
3945
+ if (tsOptchain.oc(canvas.getDimensionsRestrictions()).fixed(false))
3946
+ return;
3947
+ var currentDimensions = canvas.getDimensions();
3948
+ var baseDimensions = canvas.getBaseDimensions();
3949
+ var textHeightIncreasePx = _(canvas.getObjectsByTypeInternal(exports.ObjectType.TEXT))
3950
+ .filter(function (text) { return text.isResizeCanvas(); })
3951
+ .reduce(function (x, text) { return x + text.getSizeIncreaseSinceCreation(); }, 0);
3952
+ var increase = baseDimensions.withSize(currentDimensions.width, 0);
3953
+ while (increase.heightPx < textHeightIncreasePx) {
3954
+ increase = increase.withSize(increase.width, increase.height + 1);
3955
+ }
3956
+ var targetHeight = increase.withSize(increase.width, baseDimensions.height + increase.height);
3957
+ if (currentDimensions.height !== targetHeight.height) {
3958
+ canvas.setDimensions(targetHeight);
3959
+ }
3960
+ canvas.getObjectsInternal().forEach(function (object) { return object.setCoords(); });
3961
+ canvas.redraw();
3962
+ };
3963
+ return ResizeCanvasLayoutFunction;
3964
+ }());
3965
+
3966
+ var AdvancedLayoutManager = /** @class */ (function (_super) {
3967
+ __extends(AdvancedLayoutManager, _super);
3968
+ function AdvancedLayoutManager(canvas) {
3969
+ var _this = _super.call(this, canvas) || this;
3970
+ _this.key = exports.LayoutManager.ADVANCED;
3971
+ _this.pinToBottom = new PinToBottomLayoutFunction();
3972
+ _this.redrawAll = new RedrawAllLayoutFunction();
3973
+ _this.repositionBorders = new RepositionBordersLayoutFunction();
3974
+ _this.repositionCutoffs = new RepositionCutoffsLayoutFunction();
3975
+ _this.repositionBackgrounds = new RepositionBackgroundsLayoutFunction();
3976
+ _this.resizeCanvas = new ResizeCanvasLayoutFunction();
3977
+ return _this;
3978
+ }
3979
+ AdvancedLayoutManager.prototype.onCanvasDimensionsChange = function () {
3980
+ this.pinToBottom.execute(this.canvas);
3981
+ this.repositionCutoffs.execute(this.canvas);
3982
+ this.repositionBorders.execute(this.canvas);
3983
+ this.repositionBackgrounds.execute(this.canvas);
3984
+ this.redrawAll.execute(this.canvas);
3985
+ };
3986
+ AdvancedLayoutManager.prototype.onTextChange = function () {
3987
+ this.resizeCanvas.execute(this.canvas);
3988
+ };
3989
+ AdvancedLayoutManager.prototype.onObjectListChange = function () {
3990
+ this.redrawAll.execute(this.canvas);
3991
+ };
3992
+ return AdvancedLayoutManager;
3993
+ }(AbstractLayoutManager));
3994
+
3995
+ exports.AbstractCanvasObject = AbstractCanvasObject;
3996
+ exports.AbstractInteractiveCanvas = AbstractInteractiveCanvas;
3997
+ exports.AbstractLayoutManager = AbstractLayoutManager;
3998
+ exports.AdvancedLayoutManager = AdvancedLayoutManager;
3999
+ exports.BackgroundImage = BackgroundImage;
4000
+ exports.Border = Border;
4001
+ exports.CanvasObjectData = CanvasObjectData;
4002
+ exports.Cutoff = Cutoff;
4003
+ exports.DefaultCanvasProfile = DefaultCanvasProfile;
4004
+ exports.Font = Font;
4005
+ exports.FontLibrary = FontLibrary;
4006
+ exports.HeadlessInteractiveCanvas = HeadlessInteractiveCanvas;
4007
+ exports.HorizontalRule = HorizontalRule;
4008
+ exports.Image = Image;
4009
+ exports.InteractiveCanvas = InteractiveCanvas;
4010
+ exports.MillimeterDimensions = MillimeterDimensions;
4011
+ exports.PixelCanvasDimensions = PixelCanvasDimensions;
4012
+ exports.Print6ColCanvasDimensions = Print6ColCanvasDimensions;
4013
+ exports.Print8ColCanvasDimensions = Print8ColCanvasDimensions;
4014
+ exports.Rectangle = Rectangle;
4015
+ exports.RichText = RichText;
4016
+ exports.SelectionData = SelectionData;
4017
+ exports.StandardLayoutManager = StandardLayoutManager;
4018
+ exports.Text = Text;
4019
+ exports.UNKNOWN_FONT = UNKNOWN_FONT;
4020
+ exports.UnknownFont = UnknownFont;
4021
+ exports.VerticalRule = VerticalRule;
4022
+ exports.isMutableBackgroundColor = isMutableBackgroundColor;
4023
+ exports.isMutableColor = isMutableColor;
4024
+ exports.isMutableImage = isMutableImage;
4025
+ exports.isMutablePosition = isMutablePosition;
4026
+ exports.isMutableStroke = isMutableStroke;
4027
+ exports.isMutableText = isMutableText;
4028
+ exports.isMutableTextStyle = isMutableTextStyle;