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